Spring 注入jdbcOperations 失败 Error creating bean with name

J2EE 码拜 5年前 (2015-04-21) 398次浏览 0个评论

Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”runtimeLogDao””: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcOperations com.tjpme.ecif.etl.dao.JdbcTemplateHelper.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.tjpme.ecif.etl.util.SpringContextHolder.init(SpringContextHolder.java:26)
at com.tjpme.ecif.etl.util.SpringContextHolder.main(SpringContextHolder.java:30)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcOperations com.tjpme.ecif.etl.dao.JdbcTemplateHelper.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
… 14 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:986)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:856)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
… 16 more

Spring 注入jdbcOperations 失败 Error creating bean with name
代码:
public class JdbcTemplateHelper {

@Autowired
private JdbcOperations jdbcOperations;

protected int update(String sql, Object… args) {
return jdbcOperations.update(sql, args);
}

Spring 注入jdbcOperations 失败 Error creating bean with name
80分
报错说
Could not autowire field: private org.springframework.jdbc.core.JdbcOperations com.tjpme.ecif.etl.dao.JdbcTemplateHelper.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
意思是没有org.springframework.jdbc.core.JdbcOperations]这个类型,你有声明这个bean吗?
@Autowired按byType自动注入!
Spring 注入jdbcOperations 失败 Error creating bean with name
引用 2 楼 longtian1213 的回复:

报错说
Could not autowire field: private org.springframework.jdbc.core.JdbcOperations com.tjpme.ecif.etl.dao.JdbcTemplateHelper.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
意思是没有org.springframework.jdbc.core.JdbcOperations]这个类型,你有声明这个bean吗?
@Autowired按byType自动注入!

JdbcOperations spring 里面的也要声明吗bean吗

Spring 注入jdbcOperations 失败 Error creating bean with name
引用 3 楼 macro_lu 的回复:
Quote: 引用 2 楼 longtian1213 的回复:

报错说
Could not autowire field: private org.springframework.jdbc.core.JdbcOperations com.tjpme.ecif.etl.dao.JdbcTemplateHelper.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
意思是没有org.springframework.jdbc.core.JdbcOperations]这个类型,你有声明这个bean吗?
@Autowired按byType自动注入!

JdbcOperations spring 里面的也要声明吗bean吗

JdbcOperations 你不声明的话,spring没办法找到的!@Autowired会在已经声明过的bean中查找和要注入类型想匹配的bean,必须有一个,且只能有一个类型匹配的,多了,少都会报错!

Spring 注入jdbcOperations 失败 Error creating bean with name
<bean id=”jdbcTemplate”
class=”org.springframework.jdbc.core.JdbcTemplate”>
<property name=”dataSource”>
<ref bean=”dataSource” />
</property>
</bean>
gaoding了  谢谢!

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Spring 注入jdbcOperations 失败 Error creating bean with name
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!