I have 2 applicationContext file under the same directory and I want to load each time one of them. what is the command I need to use in order to run the application context from a command line? is there changes in the classpath?
Asked
Active
Viewed 179 times
2 Answers
0
Pass the name of your ApplicationContext
file in main
method by String[] args
parameter.
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(args[1]);
}

user2550754
- 884
- 8
- 15
0
to expand on user2550754's answer a little; ClassPathXmlApplicationContext
can take an array of String
locations of XML files (new ClassPathXmlApplicationContext(String...)
) as such, if you wanted to use the following command;
java MyApp [spring-context-file-1] [spring-context-file-2]
you could use this
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(args);
//now your context is up and initialized
}
this would pass [spring-context-file-1], [spring-context-file-2] and any others in the arguments into the ApplicationContext

incomplete-co.de
- 2,137
- 18
- 23