如何解决Spring 2.3.4.RELEASE,Mybatis.Spring.boot 2.1.3:需要属性'sqlSessionFactory'或'sqlSessionTemplate'
我正在使用想法基于Mybatis演示项目构建工件。 这实际上是一个简单的演示,其中包含:
主类:
@MapperScan(basePackages = "thusca.testMybatis.mapper")
@SpringBootApplication()
public class SampleMybatisApplication{
public static void main(String[] args) {
SpringApplication.run(SampleMybatisApplication.class,args);
}
}
映射器:
@Mapper
public interface CityMapper {
@Select("SELECT * FROM CITY WHERE state = #{state}")
City findByState(@Param("state") String state);
}
型号:
public class City implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String name;
private String state;
...
}
服务:
@Service
public class MysqLService{
@Autowired
CityMapper mapper;
}
当我使用GUI模式运行它时,它可以正确运行。但是,如果我构建工件并使用命令java -jar xxx.jar
运行它。它总是失败,并报告错误ava.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
。
这是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testxxx</groupId>
<artifactId>testMybatis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testMybatis</name>
<description>testxxx.testMybatis</description>
<properties>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>MysqL</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
</dependencies>
</project>
和application.properties
server.port=8083
spring.datasource.url=jdbc:MysqL://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=xxxxxx
spring.datasource.driver-class-name=com.MysqL.cj.jdbc.Driver
spring.datasource.max-idle=10
spring.datasource.max-wait=1000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
server.session.timeout=10
server.tomcat.uri-encoding=UTF-8
ps:对于我的项目,只能使用构想来构建工件(jar),而不能使用mvn命令。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。