我有一個GenericServlet類,用@Configurable註解,它有一個叫做dao的字段,它在春天被自動裝入,但它在使用它時不會自動裝入,而不會拋出nullpointerexception。我試圖使用@Qualifier強制執行Spring DI,但它仍然返回null;可配置的自動佈線空指針異常
@Configurable
public class GenericServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Autowired
@Qualifier("genericDaoImpl")
private GenericDAO dao;
}
@Repository
@Qualifier("genericDaoImpl")
@Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.DEFAULT, rollbackFor={Exception.class, SQLException.class, DataAccessException.class}, timeout=9999)
public class GenericDAOImpl implements GenericDAO {
@Autowired
@Qualifier("jdbcTemplate")
private JdbcTemplate jdbcDao;
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
<!-- Enable Spring Application Context -->
<context:spring-configured />
<!-- Enable @Required @Autowired @PreDestroy @PostConstruct @Resource -->
<context:annotation-config />
<!-- Scan class file in class path for annotated component -> @Component, @Repository, @Service, and @Controller -->
<context:component-scan base-package="com.breeze.bis.core.service.jdbcTemplate" />
<!-- Enable load time weaving for @Configurable -->
<context:load-time-weaver aspectj-weaving="autodetect" />
<!-- Alternate method to enable @Autowired -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/vbossdb" />
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="user" value="root" />
<property name="password" value="root" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg type="javax.sql.DataSource" ref="dataSource"></constructor-arg>
</bean>
<bean id="genericDaoImpl" class="com.breeze.bis.core.service.jdbcTemplate.GenericDAOImpl">
<property name="jdbcDao" ref="jdbcTemplate"></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="WEB-INF/ehcache.xml"></property>
<property name="shared" value="true"></property>
</bean>
</beans>
請讓我知道這個配置有什麼問題。
謝謝。
任何人都請幫忙。謝謝。 – peterwkc
任何人都請幫忙。謝謝。 – peterwkc