比方说,我有一个Spring Boot Web应用程序-它可以通过gradle(嵌入式tomcat)运行。 但我还需要以标准方式将战争部署到应用服务器中。 该应用程序应如何配置?标准的web.xml和xml配置?
目前我有类似的东西
@SpringBootApplication
公共类MyApplication扩展了SpringBootServletInitializer {
public static void main(String[] args) {
System.setProperty("spring.profiles.active", "dev");
SpringApplication.run(MyApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
@Configuration
@ConditionalOnWebApplication
public static class WebConfiguration {
@Bean
public ServletListenerRegistrationBean<ServletContextListener> registerClientCookieConfigListener () {
ServletListenerRegistrationBean<ServletContextListener> srb =
new ServletListenerRegistrationBean<>();
srb.setListener(new MyConfigListener());
return srb;
}
@Bean
public ServletListenerRegistrationBean<HttpSessionListener> registerMySessionConfigListener () {
ServletListenerRegistrationBean<HttpSessionListener> srb =
new ServletListenerRegistrationBean<>();
srb.setListener(new MySessionConfigListener());
return srb;
}
@Bean
public FilterRegistrationBean registerLoginFilter() {
FilterRegistrationBean filter = new FilterRegistrationBean(new MyFilter());
filter.setUrlPatterns(Collections.singletonList("/*"));
return filter;
}
@Bean
public ServletRegistrationBean registerSAMLDispatcherServlet() {
ServletRegistrationBean bean = new ServletRegistrationBean(
new DispatcherServlet(), "/test/*");
bean.setLoadOnStartup(1);
return bean;
}
}
}
,即1:1映射到web.xml。 甚至可以在没有web.xml的情况下将其部署到应用服务器?
答案 0 :(得分:1)
您不需要web.xml即可将Spring Boot部署到独立的tomcat服务器或任何其他Web服务器。
spring boot不依赖xml配置,它会自动配置与分派器servlet等效的对象。
要将Spring Boot应用程序部署到另一台服务器,您需要更新包装以在Maven中发动战争
<packaging>war</packaging>
并告诉Maven,Web服务器将在运行时可用,并且不要将其与范围provided
一起打包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
少量文档
https://www.baeldung.com/spring-boot-war-tomcat-deploy
https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/