SpringBoot Pom.xml文件常用配置

本文介绍了一个使用SpringBoot搭建的应用案例,该应用集成了MyBatis作为持久层框架,并使用Thymeleaf作为模板引擎。文章详细列出了项目的Maven依赖配置,包括核心库、测试工具、数据库连接、热部署工具等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cn.com.sinosoft</groupId>
    <artifactId>SpringCloud_CustomSystem</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <build>
        <finalName>springbootjsp</finalName>
    </build>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <!-- springboot 基础父类starter -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
        <relativePath />
    </parent>

    <dependencies>
        <!-- junit测试依赖 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- springboot mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
         <!-- 热部署 -->
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- springboot web依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- springboot servlet依赖 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <!-- springboot 内置tomcat依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- springboot jsp依赖 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
          <!-- thymeleaf模板引擎 -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-thymeleaf</artifactId>
          </dependency>
            <!--  配置这个才可以用html-->
        <dependency>
           <groupId>net.sourceforge.nekohtml</groupId>
           <artifactId>nekohtml</artifactId>
           <version>1.9.22</version>
        </dependency>
        
         <!-- 下面两个引入为了操作数据库 -->
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-data-jpa</artifactId>
           </dependency>
           <dependency>
               <groupId>mysql</groupId>
               <artifactId>mysql-connector-java</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-logging</artifactId>
           </dependency>

  <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
             <version>4.5.2</version>
           </dependency>
    </dependencies>
    <!-- maven插件 -->
    <build>
        <plugins>
            <plugin>
                 <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                        <!-- 热部署 -->
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>springloaded</artifactId>
                            <version>1.2.6.RELEASE</version>
                        </dependency>
                    </dependencies>
            </plugin>
        </plugins>

    </build>
</project> 

### Spring Boot 项目中 `pom.xml` 文件的作用及功能 #### 1. 基础结构定义 `pom.xml` 是 Maven 构建工具的核心配置文件,用于描述项目的元数据、依赖关系以及构建过程。在 Spring Boot 项目中,`pom.xml` 承担了以下几个主要职责: - **项目基本信息**:包括项目的名称、ID 和版本号等核心信息。这些字段帮助区分不同的模块或子项目,并便于团队协作和管理。 ```xml <groupId>com.example</groupId> <artifactId>demo-project</artifactId> <version>0.0.1-SNAPSHOT</version> ``` 以上片段展示了如何定义一个简单的 Java 应用程序的基本坐标[^1]。 #### 2. 继承与依赖管理 通过引入 `spring-boot-starter-parent`,`pom.xml` 实现了对整个项目生命周期的有效管控。具体表现为以下几点: - **统一版本控制**:父 POM (`spring-boot-starter-parent`) 预先设置了大量常用库的稳定版本组合,减少了因版本冲突引发的问题风险。 - **传递性依赖解析**:当添加某个 starter (如 spring-boot-starter-web) 后,Maven 将自动拉取所有必要的间接依赖项而无需显式声明每一个具体的 jar 包名及其对应版次[^3]。 示例代码如下所示: ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.0</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> ``` 这里只需要简单加入 web 开发所需的支持包即可快速搭建 RESTful API 接口服务端框架环境[^4]。 #### 3. 插件集成支持 为了进一步提升开发效率,`pom.xml` 还集成了多种实用型插件来辅助完成特定任务。例如: - **Spring Boot Maven Plugin**: 主要负责将应用程序构建成独立运行形式(JAR/WAR),并且能够轻松启动嵌入式的 Tomcat/Undertow 等容器实例来进行本地调试验证工作流程。 ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> ``` 这段脚本确保每次执行 mvn clean install 操作之后都会生成可供直接部署使用的成品档案文件[^5]。 --- ####
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值