现象描述:本地编译器中正常运行,打包成war放到tomcat下启动报错
报错信息:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tk.mybatis.mapper.autoconfigure.MapperAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'mybatis-tk.mybatis.mapper.autoconfigure.MybatisProperties': Could not bind properties to 'MybatisProperties' : prefix=mybatis, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'mybatis.configuration.mapped-statements[0].parameter-map.parameter-mappings[0]' to org.apache.ibatis.mapping.ParameterMapping
Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'mybatis-tk.mybatis.mapper.autoconfigure.MybatisProperties': Could not bind properties to 'MybatisProperties' : prefix=mybatis, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'mybatis.configuration.mapped-statements[0].parameter-map.parameter-mappings[0]' to org.apache.ibatis.mapping.ParameterMapping
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'mybatis.configuration.mapped-statements[0].parameter-map.parameter-mappings[0]' to org.apache.ibatis.mapping.ParameterMapping
Caused by: java.lang.IllegalStateException: Failed to extract parameter names for org.apache.ibatis.mapping.ParameterMapping(org.apache.ibatis.mapping.ParameterMapping$1)
错误信息分析:创建controller层 service层bean失败,因为创建sqlfactorybean失败,sql创建不成功的原因是mybatis中的参数无法绑定
问题分析:对比之前的项目,这个新建的项目没有任何的不同,唯一的不同时spring-boot自动使用了2.2.0release版本,而之前的是1.7.0release版本,那就把boot也改成1.7.0版本吧
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
注意:2.2.0版本和1.7.0的test依赖有点区别,下面是2.2.0的test依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
//test
package cn.ipanel.asset;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AApplicationTests {
@Test
void contextLoads() {
}
}
如果改为1.7.0,test会报错
package cn.ipanel.asset;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@SpringBootTest()
@RunWith(SpringJUnit4ClassRunner.class)
public class AApplicationTests {
@Test
public void contextLoads() {
}
}
改成1.7.0版本问题解决。