修改pom添加SpringBoot配置文件常见问题(待补)
修改pom1.升级spring全家桶到5.0以上(spring-web,spring-webmvc,spring-tx,spring-jdbc,spring-expression,spring-core,spring-context-support,spring-context,spring-beans,spring-aspects,spring-aop)等
2.引入SpringBoot,MybatisPlus
org.springframework.boot spring-boot-starter-data-redis ${springboot.version} org.springframework.boot spring-boot-configuration-processor ${springboot.version} org.springframework.boot spring-boot-starter-web ${springboot.version} org.springframework.boot spring-boot-starter-tomcat ${springboot.version} provided org.springframework.boot spring-boot-autoconfigure ${springboot.version} com.baomidou mybatis-plus-boot-starter ${mybatis-plus} com.baomidou mybatis-plus-generator ${mybatis-plus}
3.如果要用SpringBoot启动类访问jsp页面,并把jsp放到SpringBoot配置的static-path-pattern路径下,需要添加以下jar,tomcat的war包启动,则不需要修改jsp路径
添加SpringBoot配置文件org.apache.tomcat.embed tomcat-embed-jasper 9.0.58 provided org.apache.tomcat.embed tomcat-embed-core 9.0.58
1.添加application.yml到web模块的resources目录下,allow-bean-definition-overriding: true必须添加
server:
port: 8080
servlet:
context-path: /test
tomcat:
uri-encoding: UTF-8
max-threads: 1000
min-spare-threads: 30
spring:
mvc:
view:
prefix: /WEB-INF/
suffix: .jsp
static-path-pattern: /static/
jmx:
default-domain: test
servlet:
multipart:
max-file-size: 2048MB
max-request-size: 2048MB
main:
allow-bean-definition-overriding: true
2.添加SpringBootApplicationConfig.java到web模块的项目包路径下, 目的是引入struts原有的配置,如项目有多个拦截器,可依次用@Bean引入,原有的拦截器可到web.xml文件查看
package net.firstelite.bicp.web.config;
import net.firstelite.bicp.web.LoginCheckFilter;
import net.firstelite.bicp.web.filter.EncodeFilter;
import org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.importResource;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
//自动扫描包路径
@ComponentScan({"net.firstelite.*"})
//引入之前已经存在的struts配置文件
@importResource(locations = {
"classpath:spring/spring-context-bundle.xml",
"classpath:struts.xml"
})
public class SpringBootApplicationConfig {
private StrutsPrepareAndExecuteFilter strutsPrepareAndExecuteFilter = new StrutsPrepareAndExecuteFilter(); //springboot启动时初始化struts2拦截器
@Bean
public ViewResolver getViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
resolver.setOrder(0);
return resolver;
}
@Bean
@Order(1)
public FilterRegistrationBean loginCheckFilter() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new LoginCheckFilter());//注册登陆拦截filter
registrationBean.addUrlPatterns("
@SpringBootApplication
public class TestApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TestApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
常见问题(待补)


