1:由于项目需要兼容老的项目需要加载servlet
根据百度各种方法添加发现不能加载init方法
最后直接手动调用init方法。
然后发现int()方法加载中需要的一些需配置变量未加载报错,修改对应servlet的加载优先级
public class SmsApplication {
public static void main(String[] args) {
SpringApplication.run(SmsApplication.class, args);
}
@Bean
public ServletRegistrationBean servletRegistrationBean() {
BatchInitServlet batchInitServlet = new BatchInitServlet();
// 注册自定义servlet,并确认uri
ServletRegistrationBean servletRegistrationBean =
new ServletRegistrationBean(batchInitServlet, "/BatchInitServlet");// ServletName默认值为首字母小写,即myServlet
//调用init()方法
batchInitServlet.init();
//降低该注册器的优先级,避免int方法中的bean未被加载
servletRegistrationBean.setLoadOnStartup(3);
return servletRegistrationBean;
}
}
下边博文有各种加载servlet的方法。