beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘bra

1.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'brandServiceImpl': Unsatisfied dependency expressed through field 'brandMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qingcheng.BrandMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1344)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:578)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qingcheng.BrandMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1509)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
	... 24 more

上面错误依赖注入出错了,不能生成类,我检查了mapper和service的对应代码–没错,最后controller的一个方法的注解不对,正确的如下:
beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘bra

2.

Error creating bean with name 'multipartResolver' defined in URL [jar:file:/D:/soft/maven/repository

严重: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multipartResolver': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.web.multipart.commons.CommonsMultipartResolver] from ClassLoader [WebappClassLoader
  context: 
  delegate: false
  repositories:
----------> Parent Classloader:
ClassRealm[plugin>org.apache.tomcat.maven:tomcat7-maven-plugin:2.2, parent: sun.misc.Launcher$AppClassLoader@18b4aac2

原因是视频说加入的applicationContext-config.xml,和正确的配置文件中不一样,改了就好哩。
还加入下面:

<bean id="ossClient" class="com.aliyun.oss.OSSClient">
	<constructor-arg index="0" value="oss-cn-beijing.aliyuncs.com"></constructor-arg>
	<constructor-arg index="1" value="AccessKeyID"></constructor-arg>
	<constructor-arg index="2" value="AccessKeySecret"></constructor-arg>
</bean>

<!--开启任务调度-->
<task:annotation-driven></task:annotation-driven>

加完要在pom.xml里添加对应依赖。就成功了

3.

如果mysql数据库无法连接,检查版本和maven配置的jdbc一样吗,
参考学习:

https://blog.csdn.net/weixin_43770545/article/details/90486809

今天写东西测试的时候发现一个问题,如下:
beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘bra
application.yml中数据源是这样配置的:
beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘bra
第一反应就是记忆中连接mysql的驱动不都是com.mysql.jdbc.Driver吗?com.mysql.cj.jdbc.Driver是什么鬼?
后来查看了一下才知道 这个跟驱动的依赖版本有关

 <dependency> 			
     <groupId>mysql</groupId> 			
     <artifactId>mysql-connector-java</artifactId>
     <scope>runtime</scope> 	
 </dependency>

com.mysql.cj.jdbc.Driver是mysql-connector-java 6
中的特性,相比mysql-connector-java 5 多了一个时区:serverTimezone,把数据源配置的驱动改一下就好了
beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘bra
这样启动就不会再报:Loading class com.mysql.jdbc.Driver’. This is deprecated.
The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is
automatically registered via the SPI and manual loading of the driver
class is generally unnecessary.
使用UTC会有8小时的时差(中国快全球标准8小时,比如:全球标准当前是上午1点,中国时间则为上午9点),可设置为北京时间东八区GMT%2B8
或者上海时间Asia/Shanghai。

总结:
com.mysql.jdbc.Driver和mysql-connector-java 5一起用。 com.mysql.cj.jdbc.Driver和mysql-connector-java 6 一起用。

上一篇:Spring系列之Spring常用注解总结


下一篇:Java 配置全局线程池出错