동일한 디렉토리에 두 개의 applicationContext 파일이 있는데 그 중 하나를로드하려고합니다. 명령 줄에서 응용 프로그램 컨텍스트를 실행하기 위해 사용해야하는 명령은 무엇입니까? classpath에 변경 사항이 있습니까?applicationContext를로드하는 방법
0
A
답변
0
ApplicationContext
파일의 이름을 main
방법으로 String[] args
매개 변수로 전달하십시오.
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(args[1]);
}
0
사용자가 2550754의 대답을 약간 확장하려면; ClassPathXmlApplicationContext
은 String
배열의 XML 파일 (new ClassPathXmlApplicationContext(String...)
)을 다음 명령을 사용하려는 경우 사용할 수 있습니다.
java MyApp [spring-context-file-1] [spring-context-file-2]
이 통과 할이
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(args);
//now your context is up and initialized
}
를 사용할 수 있습니다 [스프링 컨텍스트 파일-1], [스프링 컨텍스트 파일-2]와에 인수 어떤 다른 사람 ApplicationContext