Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 2.3.4.RELEASE,Mybatis.Spring.boot 2.1.3:Property';sqlSessionFactory';或';sqlSessionTemplate';必须_Spring_Spring Boot_Intellij Idea_Mybatis_Spring Mybatis - Fatal编程技术网

Spring 2.3.4.RELEASE,Mybatis.Spring.boot 2.1.3:Property';sqlSessionFactory';或';sqlSessionTemplate';必须

Spring 2.3.4.RELEASE,Mybatis.Spring.boot 2.1.3:Property';sqlSessionFactory';或';sqlSessionTemplate';必须,spring,spring-boot,intellij-idea,mybatis,spring-mybatis,Spring,Spring Boot,Intellij Idea,Mybatis,Spring Mybatis,我正在使用idea基于Mybatis演示项目构建工件。 它实际上是一个简单的演示,包含: 主要类别: @MapperScan(basePackages = "thusca.testMybatis.mapper") @SpringBootApplication() public class SampleMybatisApplication{ public static void main(String[] args) { SpringApplicatio

我正在使用idea基于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-jarxxx.jar
运行它。它总是失败并报告错误
ava.lang.IllegalArgumentException:需要属性'sqlSessionFactory'或'sqlSessionTemplate'。

我在谷歌上搜索了一下,尝试了所有的解决方案,但没有一个奏效

这是我的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>


ps:对于我的项目,只有idea可以用来构建工件(jar),mvn命令不能使用。

1缺少的是
spring boot maven pugin
来构建一个合适的spring boot jar。@M.Deinum但是我必须使用idea来构建jar而不是mvn命令。你需要使用maven,否则你就没有合适的jar了。因此,要么从Intellij中运行maven,要么使用命令行。还有,为什么创建jar很重要?您使用的是maven,这应该用于创建jar,否则使用maven不会增加太多。d@M.Deinum我的项目依赖于一个特殊的jar文件,如果我使用mvnThen打包整个项目,它将崩溃。您不能使用springboot,因为它需要一个特殊打包的jar。为什么用mvn打包时会失败。那你应该把它修好
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