我正在使用springboot2.0和tomcat9将war部署到本地机器上的tomcat服务器上。我有servletcontextlistener类来初始化应用程序。应用程序在嵌入式tomcat服务器上运行良好,但是外部tomcat服务器不执行servletcontextlistener类。我没有得到任何错误,tomcat启动时没有任何异常/错误。请告知。
配置类
@NotNull
@Bean
ServletListenerRegistrationBean<ServletContextListener> myServletListener() {
System.out.println("Loading server listener.......................");
ServletListenerRegistrationBean<ServletContextListener> srb = new
ServletListenerRegistrationBean<>();
srb.setListener(new MyAppServletContextListener());
return srb;
}
下面的主spring引导类和扩展的springbootservletinitializer使应用程序能够部署到tomcat服务器。
@SpringBootApplication
public class MainSpringBootWebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
Map<String, String> nv = System.getenv();
String configlocation = nv.get("SPRING_CONFIG_LOCATION");
String configpath = configlocation + File.separator + "appilcation.properties";
if(configlocation !=null && !configlocation.isEmpty()) {
Properties props = new Properties();
props.setProperty("spring.config.location", configpath);
applicationBuilder.application().setDefaultProperties(props);
}
return applicationBuilder.sources(MainSpringBootWebApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(MainSpringBootWebApplication.class, args);
}
暂无答案!
目前还没有任何答案,快来回答吧!