方式一、简单、快速、粗暴
1、添加启动类,示例
/**
* 任务端启动类
* @author zangzhonghua
*/
@ImportResource("classpath:spring-config.xml")
@SpringBootApplication
public class TaskApplication {
private static Logger LOG = LoggerFactory.getLogger(TaskApplication.class);
public static void main(String[] args) throws Exception {
SpringApplication.run(TaskApplication.class, args);
LOG.info("TaskApplication 启动成功");
}
}
2、web.xml - servlet 、Filter 转换为 springboot
以下配置类替换你的web.xml,相关初始参数 跟着感觉设置 … 哈哈
@Configuration
public class MvcConfig extends SpringBootServletInitializer {
private static Logger LOG = LoggerFactory.getLogger(MvcConfig .class);
//注册Servlet
@Bean
public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {
ServletRegistrationBean reg = new ServletRegistrationBean(dispatcherServlet);
reg.setName("springMVC");
reg.addInitParameter("contextConfigLocation","classpath:spring-config-mvc.xml");
reg.setLoadOnStartup(1);
reg.addUrlMappings("/");
return reg;
}
//Filter注册
@Bean
public FilterRegistrationBean encodingFilter(){
CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
FilterRegistrationBean filterRegister = new FilterRegistrationBean();
filterRegister.setFilter(encodingFilter);
filterRegister.addInitParameter("encoding","UTF-8");
filterRegister.addInitParameter("forceEncoding","true");
filterRegister.addUrlPatterns("/*");
return filterRegister;
}
}
方式二、去除所有 spring-config-mvc.xml中配置,替换JavaBean配置
待续…