Spring Boot整合 pom.xml总结

博客围绕Spring Boot展开,但具体内容缺失。Spring Boot是后端开发中常用框架,能简化开发流程,提高开发效率。

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

Spring Boot整合 pom.xml总结

<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>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.10.RELEASE</version>
	</parent>
	<groupId>com.study</groupId>
	<artifactId>spring-boot-study</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<java.version>1.7</java.version>
		<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
		<thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version>
	</properties>

	<dependencies>
		<!-- springBoot的启动器 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		
		<!-- Spring Boot 整合 Junit 单元测试 -->
		<!-- 测试工具的启动器 (添加 junit 环境的 jar 包) -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
		</dependency>

		<!-- Spring Boot 整合Mybatis(持久层一) -->
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>1.1.1</version>
		</dependency>
		<!-- mysql 数据库驱动 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!-- druid数据库连接池 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.9</version>
		</dependency>

		<!-- Spring Boot 整合JPA(持久层二) -->
		<!-- JPA 的启动器 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<!-- mysql 数据库驱动 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!-- druid数据库连接池 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.9</version>
		</dependency>

		<!-- Spring Boot 整合视图层技术 -->
		<!-- Spring Boot 整合JSP技术(1) -->
		<!-- jstl -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<!-- jasper -->
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<scope>provided</scope>
		</dependency>

		<!-- Spring Boot 整合Freemarker(2) -->
		<!-- freemarker 启动器的坐标 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-freemarker</artifactId>
		</dependency>

		<!-- Spring Boot 整合thymeleaf(3) -->
		<!-- thymeleaf的启动器 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

		<!-- Spring Boot 热部署 -->
		<!-- 方式二:devtools 的依赖-->
		<!-- DevTools 的坐标 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency>

		<!-- Spring Boot 整合 Ehcache -->
		<!-- Spring Boot 缓存支持启动器 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-cache</artifactId>
		</dependency>
		<!-- Ehcache 坐标 -->
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache</artifactId>
		</dependency>

		<!-- Spring Boot 整合 Redis -->
		<!-- Spring Data Redis 的启动器 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>

		<!-- Spring Boot 整合 Scheduled 定时任务器 -->
		<!-- 添加 Scheduled 坐标 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
		</dependency>

		<!-- Spring Boot 整合 Quartz 定时框架 -->
		<!-- Quartz 坐标 -->
		<dependency>
			<groupId>org.quartz-scheduler</groupId>
			<artifactId>quartz</artifactId>
			<version>2.2.1</version>
			<exclusions>
				<exclusion>
					<artifactId>slf4j-api</artifactId>
					<groupId>org.slf4j</groupId>
				</exclusion>
			</exclusions>
		</dependency>
		<!-- 添加 Scheduled 坐标 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
		</dependency>
		<!-- Sprng tx 坐标 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
		</dependency>

	</dependencies>

	<!-- Spring Boot 热部署 -->
	<!-- 方式一:以maven 插件方式使用 SpringLoader-->
	<!-- 启动方式:使用 maven 的命令起来启动 (spring-boot:run) -->
	<!-- springloader 插件 -->
	<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.5.RELEASE</version>
					</dependency>
				</dependencies>
			</plugin>
		</plugins>
	</build>
</project>
<think>好的,用户现在的问题是关于如何在pom.xml中添加spring-boot-starter的依赖。让我先仔细看一下用户提供的引用内容,以及之前的问题记录。 用户提到的引用[1]中提到,他们在使用Spring Boot 1.5.9版本时,添加了spring-boot-starter-data-jpa依赖,但无法使用@Entity。这可能是因为依赖配置不正确或者版本问题。同时,引用[2]和[3]解释了spring-boot-starter-parent的作用,说明父POM提供了依赖管理和默认配置,这可能是正确配置依赖的关键。 用户现在的问题是如何在pom.xml中添加spring-boot-starter的依赖。首先,我需要确定用户具体需要哪个starter。Spring Boot有多个starter,比如web、data-jpa等。根据常见情况,可能用户需要的是基本的starter,但更常见的是web starter。不过用户之前的问题是关于data-jpa的,可能需要更具体的指导。 根据引用[3],添加依赖时不需要指定版本号,因为父POM已经管理了版本。所以正确的做法是在dependency中省略version标签,让父项目自动管理版本。例如,引用[3]中的示例展示了如何添加spring-boot-starter-web依赖,没有版本号。 另外,用户可能在父项目中使用了旧版本1.5.9,这可能导致依赖冲突或缺失。引用[1]提到他们使用的parent是1.5.9,但可能现在需要升级到更新的版本,比如2.x,特别是如果用户遇到了@Entity的问题,这可能是因为JPA API的版本不兼容。不过用户当前的问题只是关于如何添加依赖,所以可能不需要涉及版本升级,但需要注意父版本是否正确。 另外,引用[5]提到了镜像配置的问题,可能需要检查Maven的settings.xml是否有正确的仓库配置,以避免依赖下载失败。但这个问题可能属于网络配置,用户当前的问题可能更多是依赖配置的语法问题。 总结步骤: 1. 确认父项目是否正确使用spring-boot-starter-parent,并指定了正确的版本。 2. 在dependencies部分添加所需的starter依赖,如spring-boot-starter-web,不需要指定版本。 3. 如果遇到@Entity问题,可能需要检查是否正确引入了spring-boot-starter-data-jpa,并且父版本是否支持JPA 2.x,因为旧版本可能依赖较旧的API。 可能用户之前的错误在于同时添加了persistence-api 1.0,这可能是过时的,应该依赖Spring Boot管理的JPA版本。所以在回答中,除了添加starter的步骤外,还需要提醒避免手动添加过时的依赖,而是依靠父POM的依赖管理。 另外,用户可能需要示例代码,所以在回答中提供具体的pom.xml片段,展示如何正确配置parent和dependency,同时指出常见的错误,比如指定版本号或缺少必要的依赖。 最后,生成相关问题,帮助用户深入解决可能遇到的其他问题,比如版本冲突、依赖管理原理等。</think>[用户可见层] ### 如何在pom.xml中添加Spring Boot Starter依赖 #### 步骤说明 1. **确认父项目配置** 在`pom.xml`中必须声明`spring-boot-starter-parent`作为父项目,以继承Spring Boot的默认依赖管理和插件配置[^2][^3]。 示例配置: ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.0</version> <!-- 推荐使用较新版本 --> <relativePath/> </parent> ``` 2. **添加Starter依赖** - 在`<dependencies>`标签内添加需要的Starter依赖,**无需手动指定版本号**(由父项目统一管理)[^3]。 - 例如添加Web模块依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 3. **避免常见错误** - 若手动指定版本号(如`<version>1.5.9</version>`),可能导致依赖冲突或API不兼容[^1]。 - 不要额外添加旧的JPA依赖(如`persistence-api 1.0`),应直接使用`spring-boot-starter-data-jpa`。 #### 完整配置示例 ```xml <?xml version="1.0" encoding="UTF-8"?> <project> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.0</version> </parent> <dependencies> <!-- Web模块 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- JPA模块 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> </dependencies> </project> ``` #### 注意事项 - 若出现依赖下载失败,需检查Maven镜像配置(例如阿里云镜像)[^5]。 - 旧版本(如1.5.9)可能导致JPA注解(如`@Entity`)无法识别,建议升级至Spring Boot 2.x。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值