好吧我已經完成了大量的Google搜索,而且我似乎無法找到明確的答案。讓我們儘可能地簡單。我有一個web.xml文件將Spring Web應用程序(web.xml)遷移到Spring Boot可執行文件夾
<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;
}
}
...我們再次爲其他Servlet做上述
我的第一個問題是如何將偵聽器「A」添加到Spring Boot並確保它運行在刷新根應用程序之前?某些配置的bean需要設置一些靜態字段(遺留代碼),並且此設置在偵聽器「A」中完成。這在使用上述web.xml作爲標準戰爭部署時可以正常工作。
此外,上面的Spring Boot設置看起來是否正確?
我需要重現上面web.xml中給出的邏輯。運行遺留代碼的偵聽器需要ServletContext,並在Spring偵聽器運行(它引導Spring)之前運行。我必須能夠重現上面在Spring Boot中給出的web.xml? – paul