怒改springMVC项目为springBoot项目

背景:公司最近在做项目升级,融合所有项目,但是目前使用的一个系统还是最原始的框架 springMVC+spring+mybatis ,前端还是jsp,easyui(技术老的掉牙),终于出手了,结果。。。就让我开始修改。

前言:首先是百度一波,看看有没有什么前车之鉴,然而失望而归,感觉都不是很符合

开干:

第一步:首先在pom文件中添加spring-boot-starter相关依赖

如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!-- spring boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!--<version>2.1.1.RELEASE</version>-->
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-legacy</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <!--<version>9.0.14</version>-->
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

 

第二步:新增启动类Application

复制代码
复制代码
@SpringBootApplication
@ImportResource(locations = {"classpath:spring-*.xml","classpath:mybatis-config.xml"})
@ServletComponentScan
public class xxSpringBootApplication {
    public static void main(String[] args) {
        SpringApplication application=  new SpringApplication(T6SpringBootApplication.class);
        application.setWebEnvironment(true);
        application.run(args);
        System.out.println("xxxxxxxxxxxxxSB");
    }
}
复制代码
复制代码

有人问,为什么要加最后一行代码,表达了愤怒的心情,控制台如果看到这句话,说明启动成功了,但是经验告诉我,看到这句话是何等的困难,都是泪

 

第三步:神器 Maven Helper 

点击启动按钮,当然是一堆报错,都是些什么NoClassDefFoundError之类的。。。这些基本都是依赖冲突的问题。

这时候一个非常牛逼的插件就开始起作用了,Maven Helper 使用方法参考 https://blog.csdn.net/u013870094/article/details/79712500

这篇文章少了一步:右击可以去除冲突

接着就是一系列的解决冲突的问题,还有一些依赖是缺少的,这个时候就需要去maven上获取 https://mvnrepository.com/search ,需要的是耐心

 

第四步:

  如果项目包含前端是jsp的,需要引入一些jsp的依赖....

 

第五步:

   如果原来项目中有一个监听类,是继承 ContextLoaderListener 类的话,是需要修改的.

  老代码:

新代码:

复制代码
复制代码
@WebListener
public class SpringContextLoaderListener implements ServletContextListener {

    private static boolean initialized = false;

    @Override
    public void contextInitialized(ServletContextEvent event) {
        System.setProperty("thumbnailator.conserveMemoryWorkaround", "true");
//        super.contextInitialized(event);
        initialized = true;
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
//        super.contextDestroyed(event);
    }

    public static boolean isInitialized() {
        return initialized;
    }

}
复制代码
复制代码

 

花了一天,终于项目正常运行了,可能还有一些隐藏的bug还没有被发现,去测试了,。...........

 

补充:项目正常运行,发现无法原来使用的log4j打印日志,在springboot项目上无法打印日志。。坑爹。  springboot的打印日志组件变成了 logback,一顿改,先引入logback相关依赖包,然后将log4j.properties转换成logback支持的logback.xml 。这里有一个官方的转换网站 :https://logback.qos.ch/translator/ 。

最坑爹的就是转换过的文件,控制台可以正常输出日志,但是无法将日志输出到文件,找了一下午,必须要添加下图中红色区域代码

Ending!!!!!!!!!!!!!!!!!

posted on   &大飞  阅读(1184)  评论(0编辑  收藏  举报

编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示