GVKun编程网logo

Spring Boot项目报错org.springframework.beans.factory.UnsatisfiedDependencyException(spring boot 报错)

15

在本文中,我们将给您介绍关于SpringBoot项目报错org.springframework.beans.factory.UnsatisfiedDependencyException的详细内容,并且

在本文中,我们将给您介绍关于Spring Boot项目报错org.springframework.beans.factory.UnsatisfiedDependencyException的详细内容,并且为您解答spring boot 报错的相关问题,此外,我们还将为您提供关于Bean实例化报错org.springframework.beans.factory.BeanCreationException、MyBatis Plus + Activiti 整合报错:org.springframework.beans.factory.UnsatisfiedDependencyException、mybatis+spring+springMVC处理org.springframework.beans.factory.BeanDefinitionStoreException:java.lan...、org.springframework.beans.factory.BeanCreationException...的知识。

本文目录一览:

Spring Boot项目报错org.springframework.beans.factory.UnsatisfiedDependencyException(spring boot 报错)

Spring Boot项目报错org.springframework.beans.factory.UnsatisfiedDependencyException(spring boot 报错)

在最近进行的一个项目中学习了使用Spring boot框架的开发,在整合Mybatis开发时,项目一启动就报如下错误:

Error starting ApplicationContext. To display the conditions report re-run your application with ''debug'' enabled.
2019-05-18 17:01:35,065 [main] [org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:858)] - [ERROR] Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''registerLoginController'': Unsatisfied dependency expressed through field ''userService''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''userServiceImpl'': Unsatisfied dependency expressed through field ''usersMapper''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''usersMapper'' defined in file [D:\IDEAProjects\mk-video\mk-video-mapper\target\classes\com\mk\mapper\UsersMapper.class]: Unsatisfied dependency expressed through bean property ''sqlSessionFactory''; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sqlSessionFactory'' defined in class path resource [tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ''sqlSessionFactory'' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ''file [D:\IDEAProjects\mk-video\mk-video-mini-api\target\classes\mapper\BgmMapper.xml]''; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mk.mapper.BgmMapper.selectByPrimaryKey
   at com.mk.Application.main(Application.java:14)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''userServiceImpl'': Unsatisfied dependency expressed through field ''usersMapper''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''usersMapper'' defined in file [D:\IDEAProjects\mk-video\mk-video-mapper\target\classes\com\mk\mapper\UsersMapper.class]: Unsatisfied dependency expressed through bean property ''sqlSessionFactory''; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sqlSessionFactory'' defined in class path resource [tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ''sqlSessionFactory'' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ''file [D:\IDEAProjects\mk-video\mk-video-mini-api\target\classes\mapper\BgmMapper.xml]''; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mk.mapper.BgmMapper.selectByPrimaryKey

... 19 more Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''usersMapper'' defined in file [D:\IDEAProjects\mk-video\mk-video-mapper\target\classes\com\mk\mapper\UsersMapper.class]: Unsatisfied dependency expressed through bean property ''sqlSessionFactory''; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sqlSessionFactory'' defined in class path resource [tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ''sqlSessionFactory'' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ''file [D:\IDEAProjects\mk-video\mk-video-mini-api\target\classes\mapper\BgmMapper.xml]''; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mk.mapper.BgmMapper.selectByPrimaryKey ... 32 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sqlSessionFactory'' defined in class path resource [tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ''sqlSessionFactory'' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ''file [D:\IDEAProjects\mk-video\mk-video-mini-api\target\classes\mapper\BgmMapper.xml]''; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mk.mapper.BgmMapper.selectByPrimaryKey ... 43 more Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ''sqlSessionFactory'' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ''file [D:\IDEAProjects\mk-video\mk-video-mini-api\target\classes\mapper\BgmMapper.xml]''; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mk.mapper.BgmMapper.selectByPrimaryKey ... 56 more Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: ''file [D:\IDEAProjects\mk-video\mk-video-mini-api\target\classes\mapper\BgmMapper.xml]''; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mk.mapper.BgmMapper.selectByPrimaryKey ... 57 more Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mk.mapper.BgmMapper.selectByPrimaryKey ... 70 more

在网上看到了许多人都经历过类似的错误,归纳起来有:

  1. Application启动类放置位置问题
  2. 注解配置不完整,如Service实现类没有加@Service,Spring boot无法扫描等
  3. 配置文件等内容有误
  4. Jar包冲突

关于这些问题可以参考这篇博客:

https://blog.csdn.net/zjh_746140129/article/details/80156223

最初本人的原因是无法使用@Autowired 在ServiceImpl中注入mapper,是因为Spring boot无法识别mapper,最后在mapper接口上加上@Repository和在Application类上加上@MapperScan(basePackges="com.mk.mapper")解决,但最后项目一直报开始提到的错误。

在确定不是以上问题后,使用debugger开始跟踪过程,发现了这个:

 

解析映射资源失败,说明我的mapper.xml文件有问题。我的mapper和pojo文件是使用Mybatis逆向工程生成的,这是之前开发Spring MVC项目时配置的一个逆向工程,生成的mapper.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.mk.mapper.BgmMapper" >
  <resultMap id="BaseResultMap" type="com.mk.pojo.Bgm" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="author" property="author" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="path" property="path" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    ......
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    ......
  </sql>
  <sql id="Base_Column_List" >
    id, author, name, path
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.mk.pojo.BgmExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from bgm
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from bgm
    where id = #{id,jdbcType=VARCHAR}
  </select>
......

可以看出来是非常长的,后来换了另一种逆向工程方式,生成的pojo类并不包含XxxExample类,并且mapper.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.mk.mapper.BgmMapper" >
  <resultMap id="BaseResultMap" type="com.mk.pojo.Bgm" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="author" property="author" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="path" property="path" jdbcType="VARCHAR" />
  </resultMap>
</mapper>

替换掉pojo和mapper之后,系统启动正常,虽然目前我还不明白这两种方式的区别以及对项目的影响,如有人知道,请不吝指教。

所以看到这里,想告诉大家的是,如果出现这个问题不是上述提到的4种常见错误外,尝试debugger一下,最好断点设置在sqlSessionFactory处,因为一般项目初始无法启动时是因为无法创建bean,这里会抛出一些错误。考虑是否是自己某些文件中的代码内容有误或者有些文件不符合规范。每个人出现错误的地方有多种,希望本篇文章可以给遇到我这种类似的问题的童鞋一种方向。

 

Bean实例化报错org.springframework.beans.factory.BeanCreationException

Bean实例化报错org.springframework.beans.factory.BeanCreationException

近日在使用Spring boot 2.0.0.RELEASE 运行时,抛出了bean注入异常

代码如下:

@Bean
public FilterRegistrationBean httpFilter(){
   FilterRegistrationBean registrationBean = new FilterRegistrationBean();
   registrationBean.setFilter(new HttpFilter());
   registrationBean.addUrlPatterns("/threadLocal/*");
   return registrationBean;
}

报错信息大致如下:

2018-03-31 14:00:30.356 ERROR 18536 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''httpFilter'' defined in com.mmall.concurrency.ConcurrencyApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.FilterRegistrationBean]: Factory method ''httpFilter'' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/Filter
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]

..........
 

查看pom文件,找到是内置的tomcat的jar所引起的冲突报错

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
</dependency>

MyBatis Plus + Activiti 整合报错:org.springframework.beans.factory.UnsatisfiedDependencyException

MyBatis Plus + Activiti 整合报错:org.springframework.beans.factory.UnsatisfiedDependencyException

 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''indexConroller'': Unsatisfied dependency expressed through field ''miaoService''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''miaoServiceImpl'': Unsatisfied dependency expressed through field ''runtimeService''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''runtimeServiceBean'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''runtimeServiceBean'' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''processEngine'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''processEngine'' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''springProcessEngineConfiguration'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''springProcessEngineConfiguration'' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''javax.persistence.EntityManagerFactory'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at com.wawj.hr.HrApplication.main(HrApplication.java:13) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.5.RELEASE.jar:2.0.5.RELEASE]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''miaoServiceImpl'': Unsatisfied dependency expressed through field ''runtimeService''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''runtimeServiceBean'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''runtimeServiceBean'' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''processEngine'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''processEngine'' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''springProcessEngineConfiguration'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''springProcessEngineConfiguration'' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''javax.persistence.EntityManagerFactory'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    ... 24 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''runtimeServiceBean'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''runtimeServiceBean'' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''processEngine'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''processEngine'' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''springProcessEngineConfiguration'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''springProcessEngineConfiguration'' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''javax.persistence.EntityManagerFactory'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    ... 37 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''processEngine'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''processEngine'' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''springProcessEngineConfiguration'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''springProcessEngineConfiguration'' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''javax.persistence.EntityManagerFactory'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    ... 50 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ''springProcessEngineConfiguration'' defined in class path resource [org/activiti/spring/boot/JpaProcessEngineAutoConfiguration$JpaConfiguration.class]: Unsatisfied dependency expressed through method ''springProcessEngineConfiguration'' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''javax.persistence.EntityManagerFactory'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    ... 64 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''javax.persistence.EntityManagerFactory'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1506) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    ... 78 common frames omitted


Process finished with exit code 0

版本信息:

Activiti:6.0.0

tknybatis:1.1.4

spring boot:2.0.5.RELEASE

报错:

mybatis和activiti集成时不会报错,但是mapper和activiti集成到一起时启动就会报错,错误信息如上。

JpaProcessEngineAutoConfiguration部分代码:

public class JpaProcessEngineAutoConfiguration {
        public JpaProcessEngineAutoConfiguration() {
        }

        @Configuration
        @ConditionalOnClass(name = {"javax.persistence.EntityManagerFactory"})
        @EnableConfigurationProperties({ActivitiProperties.class})
        public static class JpaConfiguration extends AbstractProcessEngineAutoConfiguration {
            public JpaConfiguration() {
            }
        }
    }

可以看到EntityManagerFactory是被@ConditionlOnClass所注解的。而EntityManagerFactory是来自于JPA相关的接口。其实这里是Activiti所做的判断,如果项目使用了JPA,那走JPA,如果没有,则走Mybatis。所以只引入Mybatis和Activiti的话项目不会报错。继续看mapper的源码,其实mapper并没有实现EntityManagerFactory接口,而是自己写了一套,而在Activiti中则认为当前项目使用的是JPA,找不到EntityManagerFactory的实现类。

我的解决办法是引入jar:

<!--没有会引起mybaits plus通用mapper和activity的冲突-->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter-jpa</artifactId>
            <version>${activiti.version}</version>
        </dependency>

 

mybatis+spring+springMVC处理org.springframework.beans.factory.BeanDefinitionStoreException:java.lan...

mybatis+spring+springMVC处理org.springframework.beans.factory.BeanDefinitionStoreException:java.lan...

java.lang.IllegalArgumentException异常有三种情况

 

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\Users\Administrator.DESKTOP-8SA67NQ\eclipse-workspace\Spring_mybatis\bin\cn\itcast\ssm\mapper\UserMapper.class];
nested exception is java.lang.IllegalArgumentException

 

1.数据传输错误,这种情况出现的很少,基本排查一下你的数据传输格式是否正确即可

 

 

 

2.第二种是在写配置文件时

<?xml version="1.0" encoding="UTF-8"?>
前面多了一个空格 ,删除空格即可
《 错误格式:空格<?xml version="1.0" encoding="UTF-8"?> 》




3第三种出现的几率为最大,是mybatis—spring的jar包与jdk,jre的版本冲突产生的,一般导致出错的版本为jdk1.8,需要修改三个地方的jdk,修改为1.7

(1)修改你的项目:右键项目选择Properties,
修改java版本为1.7



(2)单击Window,选择Preferences,修改java选项中的Compiler中jdk版本和Installed JREs中的jdk版本。最后保存











(3)
修改tomcat服务器运行jre版本,往往好多人在看了其他的博友都没有修改tomcat中的jre版本,程勋依旧会报错的,
本身程序依靠tomcat服务器运行,只有保证程序和服务器端一致才可以。
单击Window,选择Preferences,选择servers





最后别忘记重启Eclipse重要的事情说三遍
!!!重启Eclipse
!!!重启Eclipse
!!!重启Eclipse





org.springframework.beans.factory.BeanCreationException...

org.springframework.beans.factory.BeanCreationException...

在启动工程的时候出现如下异常:

org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name ''userServiceImpl'': Injection of autowired dependencies failed;
  nested exception is org.springframework.beans.factory.BeanCreationException:
  Could not autowire field: private cn.itcast.bos.dao.IUserDao cn.itcast.bos.service.impl.UserServiceImpl.userDao;
  nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''userDaoImpl''
  defined in URL [jar:file:/D:/Maven/repository/cn/itcast/bos-dao/1.0-SNAPSHOT/bos-dao-1.0-SNAPSHOT.jar!/cn/itcast/bos/dao/impl/UserDaoImpl.class]:
  Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: ''sessionFactory'' or ''hibernateTemplate'' is required

  项目中所有Dao实现类都继承了自定义的BaseDaoImpl,而BaseDaoImpl又继承了HibernateDaoSupport 
  以前写配置文件时,sessionFactory需要单独配置,现在全注解方式,如何设置sessionFactory呢? 
  在BaseDaoImpl中增加如下方法,使用Resource:

//根据类型注入spring工厂中的会话工厂对象sessionFactory
@Resource
public void setMySessionFactory(SessionFactory sessionFactory) {
    super.setSessionFactory(sessionFactory);
}

 

 

 

  参考:https://bjyzxxds.iteye.com/blog/1163794

关于Spring Boot项目报错org.springframework.beans.factory.UnsatisfiedDependencyExceptionspring boot 报错的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Bean实例化报错org.springframework.beans.factory.BeanCreationException、MyBatis Plus + Activiti 整合报错:org.springframework.beans.factory.UnsatisfiedDependencyException、mybatis+spring+springMVC处理org.springframework.beans.factory.BeanDefinitionStoreException:java.lan...、org.springframework.beans.factory.BeanCreationException...的相关知识,请在本站寻找。

本文标签: