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)} |
|
代码:
public class JdbcTemplateHelper { @Autowired protected int update(String sql, Object… args) { |
|
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自动注入! |
JdbcOperations spring 里面的也要声明吗bean吗 |
|
JdbcOperations 你不声明的话,spring没办法找到的!@Autowired会在已经声明过的bean中查找和要注入类型想匹配的bean,必须有一个,且只能有一个类型匹配的,多了,少都会报错! |
|
<bean id=”jdbcTemplate”
class=”org.springframework.jdbc.core.JdbcTemplate”> <property name=”dataSource”> <ref bean=”dataSource” /> </property> </bean> gaoding了 谢谢! |