# Spring Boot常用设置

# 热部署

在pom.xml中添加依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>


       <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <fork>true</fork> <!-- IDEA,如果没有该配置,devtools不会生效 还需要开启自动编译Build project automatically -->
                        <addResources>true</addResources>
                    </configuration>
                </plugin>
            </plugins>
        </build>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 捕获异常并回滚

	@Transactional(rollbackFor = Exception.class)
	public void test() {
		try {
			updata();
			updata2();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			// 如果updata2()抛了异常,updata()会回滚,不影响事物正常执行
		}
	}
1
2
3
4
5
6
7
8
9
10
11

若缺失依赖

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
		</dependency>
1
2
3
4

# web依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
1
2
3
4

# mybatis 的mapperXml配置

pom.xml

    <build>
        <!--resources配置解决mybatis 的mapperXml配置在java路径不被扫描的问题 -->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# maven项目打包配置

pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!--跳过测试 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16