2013-01-10 2 views
0

스프링에 의해 자동으로 실행되는 dao라는 필드가있는 @Configurable로 주석 된 GenericServlet 클래스가 있지만 사용시 nullpointerexception을 던지기보다는 자동으로 autowired를 얻지는 않습니다. @Qualifier를 사용하여 Spring DI를 시행하려고했지만 여전히 null을 반환합니다.Configurable Autowired NullPointerException

@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> 

이 구성에 대한 잘못된 점을 알려주십시오.

감사합니다.

+0

누구든지 도와주세요. 감사. – peterwkc

+0

누구든지 도와주세요. 감사. – peterwkc

답변

1

스프링 어노테이션을 올바르게 기억하면 식별하려는 빈에 대해 @Qualifier이 실행되지 않습니다. 오히려 @Repository("genericDaoImpl")처럼 주석을 달아야합니다.

+0

시도했지만 여전히 동일한 오류가 있습니다. 로깅이나 수동으로 인스턴스를 생성하는 것과 같은 진단 방법은 무엇입니까? 스택 추적 또는 로그 없음 – peterwkc

+0

GenericServlet에서 setter를 사용하여 Autowired를 변경하고 setter가 호출되지 않습니다. – peterwkc

+0

누구든지 도와주세요. 감사. – peterwkc