Dealing with command line arguments and Spring

前端 未结 7 630
孤街浪徒
孤街浪徒 2020-12-13 04:19

When I\'m writing a Spring command line application which parses command line arguments, how do I pass them to Spring? Would I want to have my main() structured so that it f

7条回答
  •  不思量自难忘°
    2020-12-13 04:51

    Here is an example to boot strap spring for a Main method, simply grab the passed params as normal then make the function you call on your bean (in the case deployer.execute()) take them as Strings or via any format you feel suitable.

    public static void main(String[] args) throws IOException, ConfigurationException {
        Deployer deployer = bootstrapSpring();
    
        deployer.execute();
    }
    
    private static Deployer bootstrapSpring()
    {
        FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext("spring/deployerContext.xml");
    
        Deployer deployer = (Deployer)appContext.getBean("deployer");
        return deployer;
    }
    

提交回复
热议问题