springboot项目war包部署及出现的问题Failed to bind properties under 'mybatis.configuration.mapped-statements[0].

1.修改pom文件
修改打包方式 为war;
添加tomcat使用范围,provided的意思即在发布的时候有外部提供,内置的tomcat就不会打包进去

   <groupId>com.school</groupId>
    <artifactId>daniel</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>daniel</name>
    <description>student information project for Spring Boot</description>
    <!--打包方式,发布时使用此项-->
    <packaging>war</packaging>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--需要发布发war包时使用-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

2.在启动类或者配置类中继承SpringBootServletInitializer ,如果需要打war包部署,需要继承此类,重写configure方法

@SpringBootApplication
public class DanielApplication extends SpringBootServletInitializer {
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DanielApplication.class);
    }
    public static void main(String[] args) {
        SpringApplication.run(DanielApplication.class, args);
    }
}

注意:
如果使用的springboot最新的版本则会报,我当时用的是
spring-boot-starter-parent:2.2.0.RELEASE,
mybatis-spring-boot-starter:2.1.1
修改为下面的版本问题解决,通过查询资料发现现在的最新版本springboot与mybatis兼容性存在问题,到后面升级后应该就没有问题了。
Failed to bind properties under 'mybatis.configuration.mapped-statements[0].parameter-map.parameter-…

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <!--<version>2.2.0.RELEASE</version>-->
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
<dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <!-- <version>2.1.1</version>-->
        <version>2.0.1</version>
</dependency>

附:以上的问题都已解决,但是我的项目中使用了shiro框架,在外置tomcat部署时,无法使用shiro。没有改版本的时候使用idea是正常的…

根据提供的引用内容,"Mapped Statements collection does not contain value for" 是一个错误信息,通常出现在使用MyBatis框架时。这个错误表示在MyBatis的映射文件中找不到对应的SQL语句。 解决这个问题的方法有以下几种: 1. 检查映射文件:确保映射文件中存在对应的SQL语句,并且语句的id与代码中调用的id一致。 2. 检查命名空间:确保映射文件中的命名空间与代码中调用的命名空间一致。 3. 检查SQL语句:确保SQL语句正确无误,括表名、列名、参数等。 4. 检查配置文件:检查MyBatis的配置文件,确保映射文件已经正确配置。 5. 检查数据库连接:确保数据库连接正常,可以连接到数据库并执行SQL语句。 6. 检查日志信息:查看MyBatis的日志信息,可以帮助定位问题所在。 下面是一个示例代码,演示了如何使用MyBatis查询数据库: ```java // MyBatis配置文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mydatabase"/> <property name="username" value="root"/> <property name="password" value="password"/> </dataSource> </environment> </environments> <mappers> <mapper resource="com/example/mapper/MyMapper.xml"/> </mappers> </configuration> // MyMapper.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.mapper.MyMapper"> <select id="getUser" resultType="com.example.model.User"> SELECT * FROM user WHERE id = #{id} </select> </mapper> // MyMapper.java package com.example.mapper; import com.example.model.User; public interface MyMapper { User getUser(int id); } // MyService.java package com.example.service; import com.example.mapper.MyMapper; import com.example.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class MyService { @Autowired private MyMapper myMapper; public User getUser(int id) { return myMapper.getUser(id); } } // MyController.java package com.example.controller; import com.example.model.User; import com.example.service.MyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @RestController public class MyController { @Autowired private MyService myService; @GetMapping("/user/{id}") public User getUser(@PathVariable int id) { return myService.getUser(id); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值