您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關SpringBoot2.1.6整合遇見的問題有哪些,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
項目配置pom文件:
<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>www.3wd.top</groupId>
<artifactId>springBoot</artifactId>
<version>springBoot-1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<properties>
<mybatis.spring.boot>2.1.0</mybatis.spring.boot>
<jdbc.driver.groupId>mysql</jdbc.driver.groupId>
<jdbc.driver.artifactId>mysql-connector-java</jdbc.driver.artifactId>
<jdbc.driver.version>8.0.16</jdbc.driver.version>
<alibaba.fastjson.version>1.2.58</alibaba.fastjson.version>
<alibaba.druid.version>1.1.18</alibaba.druid.version>
<javax.persistence.api>1.0.2</javax.persistence.api>
<tk.mybatis.version>2.1.5</tk.mybatis.version>
<com.github.pagehelper.version>1.2.12</com.github.pagehelper.version>
<org.mybatis.generator.version>1.3.7</org.mybatis.generator.version>
<com.google.guava.version>28.0-jre</com.google.guava.version>
</properties>
<dependencies>
<!--Spring Boot strat -->
<!-- Web場景啟動器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MyBatis 啟動器 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.spring.boot}</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>${tk.mybatis.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${com.github.pagehelper.version}</version>
</dependency>
<!-- Mybatis Generator -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${org.mybatis.generator.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<!--spring切面aop依賴 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- SpringBoot 的測試依賴 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 德魯伊連接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${alibaba.druid.version}</version>
</dependency>
<!-- MYSQL -->
<dependency>
<groupId>${jdbc.driver.groupId}</groupId>
<artifactId>${jdbc.driver.artifactId}</artifactId>
<version>${jdbc.driver.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!--常用庫依賴 -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${javax.persistence.api}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${com.google.guava.version}</version>
</dependency>
</dependencies>
<!-- 需要將包類型改為 jar 包 <packaging>jar</packaging> <build> <finalName>api</finalName> <resources> <resource> <directory>src/main/resources</directory>
<filtering>true</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <fork>true</fork> <mainClass>top.www.webapp.pay.controller.Application</mainClass> 指定啟動的類 </configuration>
<executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId>
<version>2.5</version> <configuration> <encoding>UTF-8</encoding> <useDefaultDelimiters>true</useDefaultDelimiters> </configuration>
</plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version>
<configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target>
</configuration> </plugin> </plugins> </build> -->
<!-- maven war包配置 -->
<packaging>war</packaging>
<build>
<finalName>top</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
問題一:
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1e0721ac] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@196918e2] will not be managed by Spring
產生原因:沒有配置事物控制
解決辦法:在啟動類中添加@EnableTransactionManagement 和實現類中添加@Transactional 聲明事務就可以了,
問題二:NoSuchMethodException: tk.mybatis.mapper.provider.base.BaseInsertProvider.<init>()
產生原因:原因是你集成使用tk.mybatis 的包,dao接口中導入的都是k.mybatis有關的包,而Application 啟動類中@MapperScan注解 導入的包是org.mybatis.spring.annotation.MapperScan。造成k.mybatis這個包中初始化失敗
解決辦法:Application 啟動類中@MapperScan注解 導包使用 import tk.mybatis.spring.annotation.MapperScan; 這個包掃描Mapper接口
問題三:使用@Slf4j注解中 log 報錯
產生原因:可能你使用的開發工具沒有集成lombok.jar
解決辦法:復制你項目中依賴lombok.jar 這個版本的jar。這里以eclipse為例:
把這個lombok.jar復制到你eclipse平級目錄中,然后在eclipse.ini加上 -javaagent:D:\eclipse-jee-2019-06\lombok.jar ,重新打開eclipse即可
lombok.jar : 下載地址 https://www.projectlombok.org/all-versions
關于SpringBoot2.1.6整合遇見的問題有哪些就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。