Reputation: 31
@SpringBootApplication
//@ImportResource({"classpath:dubbo.xml"})
//I want to specify the xml file with command line arguments at run time
public class App {
public static void main(String[] args) {
// How to import the XML file now?
SpringApplication.run(App.class, args);
}
}
I want to specify the XML file with command line arguments at run time then import it in main method. What can I do?
Upvotes: 3
Views: 1614
Reputation: 49341
You can do it this way:
SpringApplication app = new SpringApplication(App.class, "classpath:dubbo.xml");
app.run(args);
The SpringApplication constructor accepts Objects. A valid source is one of: a class, class name, package, package name, or an XML resource location (see e.g. SpringApplication.setSources).
If you would like to make the configuration file configurable by command line arguments you need to parse the arguments and adjust parameter values of course.
Upvotes: 1