栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

基于maven把struts2项目升级为SpringBoot2.0+MybatisPlus项目

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于maven把struts2项目升级为SpringBoot2.0+MybatisPlus项目

基于maven把struts2项目升级为SpringBoot2.0+MybatisPlus项目

修改pom添加SpringBoot配置文件常见问题(待补)

修改pom

1.升级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路径

			
                org.apache.tomcat.embed
                tomcat-embed-jasper
                9.0.58
                provided
            
            
                org.apache.tomcat.embed
                tomcat-embed-core
                9.0.58
            
添加SpringBoot配置文件

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);
    }
}

常见问题(待补)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/785636.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号