springboot2.0要求要jdk1.8版本以上,所我们不能用springboot2.X系列
一开始用了2.0.0,发现并jdk1.6并不能用springboot2.0.0,所以我用了springboot1.4.5,1.4.5只支持Tomcat7,以下项目pom依赖引入
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
但是还有加以下两个依赖,不然会报错
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
在这个时候我又引入mybatis-spring-boot-starter 1.3.2来使用mybatis,但是发现不能找到mapper实例,报如下错误,一顿错误狂找,没有发现问题
ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dsmController': Unsatisfied dependency expressed through field 'signedMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'signedMapper' defined in file [F:\Users\Because of you\ide\driverstudymanager\target\classes\com\qy\dsm\mapper\SignedMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$81f3911e]: Constructor threw exception; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'java.lang.Object' available: expected single matching bean but found 4: &signedMapper,systemEnvironment,contextParameters,contextAttributes
我觉得是版本配套问题吧,我把mybatis-spring-boot-starter 1.3.2换成mybatis-spring-boot-starter 1.1.1,结果tm神奇的可以了,能用自动注入实例了。
使用mybatis *Mapper.xml这种方式一定注意xml文件的位置,application.yml配置一定要正确,不然会包Invalid bound statement (not found),关联不到xml文件
mybatis:
mapper-locations:classpath:mybatis/mapper/*.xml
type-aliases-package:
config-location:classpath:mybatis/mybatis-config.xml
反正jdk1.6使用springboot坑挺多的,咱也不知道,咱也不敢问啊!