문제 :
스프링 컨테이너를 주입하는 리스너를 초기화하는 데이터 객체, 먼저 수신기 초기화 데이터를 사용할 수있는 스프링 컨테이너를 시작해야합니다.
해결 방법 :
스프링 프레임을 시작하는 리스너를 사용하여
문제 : 매개 변수를 시작하는 데 필요한 스프링 프레임 워크?
1. 필요성은 구성 파일 또는 구성 클래스의 위치를 지정
2. 주석 구성 피곤 사용하는 경우, 컨테이너의 형식을 수정해야
질문 : 초기화 매개 변수를 지원하지 않습니다 청취자입니다. 어떻게 내부의 리스너에 매개 변수를 전달하는 방법?
A는 : 내부 글로벌 컨텍스트 파라미터를 다시 설정함으로써, 수신기의 ContextLoaderListener는 문맥 파라미터를 획득하여이 문제를 해결하는 것으로
< 상황 PARAM > < PARAM 이름 > 하여 contextConfigurationLocation </ PARAM 이름 // 해당 스프링 컨트롤러의 선단부 <PARAM-value>는 쓰지 유의> < PARAM 값 > org.chu.config </ PARAM 값 > </ 문맥 PARAM > < 컨텍스트 PARAM > < PARAM 이름 > contextClass에 </ PARAM 이름 > < PARAM 값 > org.springframework.web.context.support.AnnotationConfigWebApplicationContext </ PARAM 값 > </ 문맥 PARAM > < 수신기 > < 리스너 클래스 > org.springframework.web.context.ContextLoaderListener </ 리스너 클래스 > </ 청취자 >
사용자 정의 데이터 초기화 리스너
공공 클래스 DataInitializeListener 구현 ServletContextListener의이 { // 봄 의존성 주입에만 스프링 컨테이너에 사용되는 객체 : 문제가. 리스너는 객체 컨테이너의 봄이 아니다. // 해결책 : 콘테이너 내의 오브젝트에 의해 얻어진 비 컨테이너 객체 컨테이너 객체 .getBean () / ** * 컨텍스트 초기화 시간 메소드 호출 * / @Override 공개 공극 contextInitialized (ServletContextEvent SCE) { System.out에 .println ( "== == 시작할" ) ServletContext 내 컨텍스트 = sce.getServletContext (); // ApplicationContext를 WebApplicationContext에서 애플리케이션 컨텍스트 = WebApplicationContextUtils.getWebApplicationContext (컨텍스트); RoleService roleService applicationContext.getBean 행 = (RoleService.클래스 ); DictionaryService dictionaryService = applicationContext.getBean (DictionaryService. 클래스 ); ModularService modularService = applicationContext.getBean (ModularService. 클래스 ); PermissionService permissionService = applicationContext.getBean (PermissionService. 클래스 ); UserService userService = applicationContext.getBean (UserService. 클래스 ); AreaService areaService = applicationContext.getBean (AreaService. 클래스 ); CustomerSerivce customerSerivce = applicationContext.getBean (CustomerSerivce. 클래스) } / ** * 때 컨텍스트 파괴 메소드 호출 * / @Override 공개 공극 contextDestroyed (ServletContextEvent SCE) { 에서 System.out.println는 ( "== == 폐색」) ServletContext 내 컨텍스트 = sce.getServletContext () ; context.removeAttribute ( "global_roles" ) context.removeAttribute ( "global_dictionarys ' ); } }