您好,登录后才能下订单哦!
这篇文章将为大家详细讲解有关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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。