스프링 빈을 사용하는 응용 프로그램을 만들고 있는데 ApplicationContext
을 xml
에서 초기화해야합니다. 그것은 서버 응용 프로그램이 아니므로 WEB-INF
폴더가 없습니다. 그래서, 어디에 xml
파일을 넣어야합니까?Spring applicationContext.xml
1
A
답변
1
확인이 예 Spring Setter Injection
는 XML이 응용 프로그램의 클래스 경로에있는 경우 다음 XML 파일 시스템에있는 경우 그렇지 않으면 다음
ApplicationContext context = new FileSystemXmlApplicationContext("beans.xml");
3
스프링을 사용하여이
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
처럼 사용 이 주제에 대한 문서는 처음에는 다소 압도적입니다. 응용 프로그램 컨텍스트 구성에 대한 봄 설명서의 편리한 시작 지점은 here
file system xml application context과 함께 시작하는 것이 가장 쉽습니다. 그래서 :
ApplicationContext appCtx =
new FileSystemXmlApplicationContext("/path/to/springconfig.xml");
사용 ClassPathApplicationContext
당신은 당신의 애플리케이션 클래스 패스에있는 XML 설정이있는 경우. 이 예제에서는 프로젝트 디렉토리 src/config/springconfig.xml 아래 springconfig.xml 일 수 있습니다. 기본 이클립스
jar -tvf myapp.jar
: 당신의 springconfig.xml이 응용 프로그램을 구축 한 후, 당신은 당신의 항아리의 내용을 나열하려면 다음 명령을 사용하여 끝 위치를 알 수없는 경우
ApplicationContext appCtx =
new ClassPathXmlApplicationContext("config/springconfig.xml");
java 프로젝트의 경우 프로젝트 홈/bin 디렉토리가 클래스 경로의 시작입니다.
이와 관련된 질문 here
3
사용 ClassPathXmlApplicationContext
질문을 받았다 :
ApplicationContext ctx =
new ClassPathXmlApplicationContext("applicationContext.xml");
또는 @Configuration
로 마이그레이션 고려 :
AppConfig
이
@Configuration
의 주석을 붙일 수
ApplicationContext ctx =
new AnnotationConfigApplicationContext(AppConfig.class);
없이 XML이 필요하다.
관련 문제
- 1. applicationcontext.xml 다른 jar에서 spring servrices
- 2. ApplicationContext.xml, DAO 및 Service가있는 Spring JPA는 NULL입니다.
- 3. 내 액션 및 서비스 클래스에서 applicationContext.xml 피하기
- 4. applicationContext.xml 파일에서 Spring bean 정의를 활성화 또는 비활성화 할 수있는 방법이 있습니까?
- 5. applicationContext.xml beans 용 스윙 에디터 UI?
- 6. Spring + Hibernate + JPA
- 7. applicationContext.xml 파일에 구성된 모든 데이터 소스 가져 오기?
- 8. 기본 컨텍스트에서 Spring ContextLoaderListener 사용하기
- 9. Spring @Profiguration을 가진 프로퍼티
- 10. 웹 응용 프로그램에 Spring AOP를로드하는 방법은 무엇입니까?
- 11. NoSuchMethodError with Spring MutableValues
- 12. Spring - applicationContext.xml과 XXXXX-servlet.xml을 사용하여
- 13. LDAP CRUD with Spring Roo
- 14. Struts2 + Spring, 스프링 플러그인이 필요합니까?
- 15. JSF + Spring + Hibernate + Existing Project
- 16. 빈이 생성자에 Spring 애플리케이션 컨텍스트를로드하려고하면 어떻게 될까?
- 17. JNLP에서 Spring 설정 파일 지정하기
- 18. 선언적 Spring 캐시 사용자 정의
- 19. 봄, new ClassPathXmlApplicationContext를 사용하고 applicationContext.xml 및 기타를 찾을 수 없다는 오류가 발생합니까?
- 20. Eclipse RCP Spring 통합 오류
- 21. Spring 2.5에서 Spring 3.0.5로 마이그레이션
- 22. Spring MVC없이 포틀릿에서 Spring 사용하기
- 23. Spring in Spring MVC 3.1.2
- 24. Spring-Dao는 Spring-mvc와는 다른가요?
- 25. Spring 3로 구성된 JPA를 얻는 방법은 무엇입니까?
- 26. Spring/Hibernate3 ManyToMany 관계 문제
- 27. Spring & Struts2 REST - junit tests
- 28. Spring JMX. XML을 통해 @ManagedAtrribute의 기본값을 설정하십시오.
- 29. Spring + Felix war = FileNotFoundException
- 30. 애플리케이션의 각 클래스는 Spring 애플리케이션 컨텍스트를 어떻게 검색해야합니까?
동일한 작업을 수행하고 src 디렉토리에 응용 프로그램 컨텍스트 xml을 넣습니다. 작동하지 않습니다. 나는 이클립스 RCP 애플리케이션을 연구 중이다. – itun
일부 클래스 경로 디버그 아이디어가 포함되도록 업데이트되었습니다. 필자는 src/config/springconfig.xml을 사용하여 Eclipse에서이를 테스트했으며 저에게 적합합니다. – pd40