快速判断一个项目是Spring MVC框架还是Spring Boot框架

1. 查看项目的启动类

Spring Boot : 通常有一个主类,包含 @SpringBootApplication 注解,并且有一个 main 方法来启动应用程序。

java 复制代码
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Spring MVC: 通常没有这样的启动类,项目的启动依赖于外部Web容器(如Tomcat)的配置。

2. 查看 pom.xmlbuild.gradle 文件

Spring Boot : 通常会有 spring-boot-starter 相关的依赖。

java 复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

Spring MVC : 依赖项通常是 spring-webmvc,而不是 spring-boot-starter

java 复制代码
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
</dependency>

3. 查看配置文件

Spring Boot : 通常使用 application.propertiesapplication.yml 文件来配置应用程序。

java 复制代码
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/db

Spring MVC : 通常使用 web.xmlapplicationContext.xml 文件来配置应用程序。

java 复制代码
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

4. 查看项目结构

Spring Boot : 项目结构通常比较简洁,主要包含 src/main/javasrc/main/resources 目录。

Spring MVC : 项目结构通常包含 src/main/webapp 目录,并且有 WEB-INF 文件夹。

5.查看依赖管理

Spring Boot : 使用 spring-boot-starter-parent 作为父项目。

java 复制代码
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
</parent>

Spring MVC : 通常使用 spring-framework-bom 或者没有特定的父项目。

java 复制代码
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>5.3.9</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

总结

通过查看项目的启动类、依赖配置、配置文件、项目结构和依赖管理,可以快速判断一个项目是Spring MVC框架还是Spring Boot框架。Spring Boot项目通常有一个带有 @SpringBootApplication 注解的启动类,使用 spring-boot-starter 相关的依赖,并且配置文件是 application.propertiesapplication.yml。Spring MVC项目通常依赖于外部Web容器,使用 spring-webmvc 依赖,并且配置文件是 web.xmlapplicationContext.xml

相关推荐
我叫张小白。9 小时前
Spring Boot拦截器详解:实现统一的JWT认证
java·spring boot·web·jwt·拦截器·interceptor
q***697711 小时前
Spring Boot与MyBatis
spring boot·后端·mybatis
r***123813 小时前
SpringBoot最佳实践之 - 使用AOP记录操作日志
java·spring boot·后端
daidaidaiyu13 小时前
Spring IOC 源码学习一 基本姿势
java·spring
间彧13 小时前
Spring AOT + GraalVM Native Image:云原生Java的效能引擎
spring
LSL666_13 小时前
SpringBoot自动配置类
java·spring boot·后端·自动配置类
q***783713 小时前
Spring Boot 3.X:Unable to connect to Redis错误记录
spring boot·redis·后端
t***265914 小时前
SpringBoot + vue 管理系统
vue.js·spring boot·后端
qq_124987075315 小时前
基于springboot的疾病预防系统的设计与实现(源码+论文+部署+安装)
java·spring boot·后端·毕业设计
q***25116 小时前
Spring Boot 集成 Kettle
java·spring boot·后端