微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring 2.3.4.RELEASE,Mybatis.Spring.boot 2.1.3:需要属性'sqlSessionFactory'或'sqlSessionTemplate'

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?