我有一堂课:
@Configuration
public abstract class JDBCConnFactory {
@Autowired
@Qualifier("dataSource")
@Bean
public SimpleJdbcOperations jdbcConnection(DataSource dataSource){
return new SimpleJdbcTemplate(dataSource);
}
}
我尝试在另一个类中使用bean jdbcConnection:
@Autowired
@Qualifier("jdbcConnection")
private SimpleJdbcOperations dbConn;
我得到了错误:
No qualifying bean of type [org.springframework.jdbc.core.simple.SimpleJdbcOperations] 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.beans.factory.annotation.Qualifier(value=jdbcConnection)}
或另一个例外:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbcConnection' is defined
我的错误在哪里?为什么找不到 jdbcConnection bean?