我在尝试将spring boot 1.4.2应用程序部署到tomcat 7时遇到此错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationServiceImpl': Unsatisfied dependency expressed through field 'applicationDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDao' defined in file [E:\sources\apache-tomcat-7.0.86\webapps\OnlineChannelBackend-0.0.1-SNAPSHOT\WEB-INF\classes\com\pack\dao\ApplicationDao.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$$f214bdd7]: 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: &applicationDao,systemEnvironment,contextParameters,contextAttributes
我的相关构建gradle:
sourceCompatibility = 1.6 //java6
targetCompatibility = 1.6
dependencies {
compile('org.springframework.boot:spring-boot-legacy:1.1.0.RELEASE')
compile('org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2')
compile('com.oracle:ojdbc6:11.1.0.7.0') //java6
providedRuntime('org.apache.tomcat:tomcat-juli:7.0.59') // java6
compile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '7.0.59'
并在com.pack.dao中我有3个用@Mapper
注释的mapper接口和资源中相应文件夹中的相应xml文件...应用程序运行良好,使用spring boot 2但是一旦我开始将其更改为spring boot 1.4.2我无法让它工作
答案 0 :(得分:1)
因为它在之前的春季版本中运行,我相信你有你的配置文件,所以你可能需要为我的batis排除spring auto configurer。
@SpringBootApplication
@EnableAutoConfiguration(exclude = {MybatisAutoConfiguration.class})