2017-09-13 2 views
0

그래, 나는 많은 검색을 해왔고 명확한 답을 찾지 못하는 것 같다. 가능한 한 간단하게 유지합시다. 나는 web.xml 파일 나는 봄 부팅이를 마이그레이션하는 방법을 알고 있다고 생각스프링 웹 애플리케이션 (web.xml)을 스프링 부트 실행 파일로 옮기기

<listener> 
    <listener-class>A</listener-class> 
</listener> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:springcontexts/*.xml</param-value> 
</context-param> 

<context-param> 
    <param-name>contextClass</param-name> 
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> 
</context-param> 

<servlet> 
    <servlet-name>spring-ws</servlet-name> 
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class> 
    <init-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:wsspringcontexts/*.xml</param-value> 
    </init-param> 
</servlet> 

<servlet> 
    <servlet-name>DispatcherServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:spring_mvc_contexts/*.xml</param-value> 
    </init-param> 
</servlet> 

... 하위 패키지

@SpringBootApplication(exclude = DispatcherServletAutoConfiguration.class) 
@ImportResource("classpath*:springcontexts/*.xml") 
public class Application 
{ 
    public static void main(String[] args) 
    { 
    SpringApplication.run(Application.class, args); 
    } 
} 

어딘가에 ...이

@Configuration 
@EnableWebMvc 
public class SpringMVCConfiguration 
{ 
    @Bean 
    public ServletRegistrationBean mvc() 
    { 
    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); 
    applicationContext.setConfigLocation("classpath*:spring_mvc_contexts/*.xml"); 
    // the dispatcher servlet should automatically add the root context 
    // as a parent to the dispatcher servlet's applicationContext 
    DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext); 
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet, "/spring/*"); 
    servletRegistrationBean.setName("DispatcherServlet"); 
    return servletRegistrationBean; 
    } 
} 

... 다른 서블릿에 대해 위의 작업을 다시 수행합니다.

첫 번째 문제점은 청취자 "A"를 Spring Boot에 추가하고 실행되도록하는 것입니다 루트 응용 프로그램이 새로 고쳐지기 전에? 일부 빈은 설정되기 위해 일부 정적 필드 (레거시 코드)가 필요하며,이 설정은 리스너 "A"에서 수행됩니다. 위의 web.xml을 사용하여 표준 전쟁으로 배포 할 때 정상적으로 작동합니다.

위의 스프링 부트 설정이 올바른지 확인하십시오.

답변

0

bean의 postConstruct 메소드에 레거시 초기화를 넣지 않는 이유는 무엇입니까?

당신이

ApplicationListener<ContextRefreshedEvent>

를 구현하고

public void onApplicationEvent(final ContextRefreshedEvent event)

이 봄 부트 설치 확인을 보입니까

무시 리스너를 추가 할 수있는 실패? 어렵지 만, 스프링 부트가 당신을위한 디스패처 서블릿과 같은 것을 자동 설정하고 모든 XML 설정을 없애 버릴 수는 있지만 말하기는 어렵습니다.

+0

위의 web.xml에 나와있는대로 논리를 재현해야합니다. 레거시 코드를 실행하는 리스너는 ServletContext가 필요하며 Spring Listener가 실행되기 전에 실행됩니다 (Spring을 부트 스트랩합니다). 스프링 부트에서 위에 주어진 web.xml을 재현 할 수 있어야합니까? – paul

관련 문제