2016-10-28 7 views
3

를 autowiring에 나는 동적으로 다음 코드를 사용하여 응용 프로그램 컨텍스트에 컨텍스트를 추가하고있다. 그러나 @Autowired는 이러한 새로운 bean에 대해 작동하지 않습니다. 빈 같이 새로운 문맥에서 정의 예컨대동적 컨텍스트

:

public class ContractMapper implements RowMapper<ContractFile> { 

    @Autowired 
    IIntegrationDao integrationDao; 

    @Override 
    public ContractFile mapRow(ResultSet rs, int rowNum) throws SQLException { 
     ...... 
    } 
} 

런타임시 outboundContractJdbcFileMapper 속성 integrationDao가 null :

<bean id="outboundContractJdbcFileMapper" class="com.......integration.model.contract.ContractMapper"/> 

는 다음에서 autowiring있다.

빈이 만들어 질 때 autowiring을 강제로 수행하는 방법이 있습니까? ctx.refresh()가이 작업을 수행하기를 바랬습니다.

답변

3

ClassPathXmlApplicationContext에 대해서는 자동으로 작동하지 않습니다. 해당 하위 컨텍스트에도 <context:annotation-config/>을 추가해야합니다.

<xsd:element name="annotation-config"> 
    <xsd:annotation> 
     <xsd:documentation><![CDATA[ 
Activates various annotations to be detected in bean classes: Spring's @Required and 
@Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available), 
JAX-WS's @WebServiceRef (if available), EJB 3's @EJB (if available), and JPA's 
@PersistenceContext and @PersistenceUnit (if available). Alternatively, you may 
choose to activate the individual BeanPostProcessors for those annotations. 

Note: This tag does not activate processing of Spring's @Transactional or EJB 3's 
@TransactionAttribute annotation. Consider the use of the <tx:annotation-driven> 
tag for that purpose. 

See javadoc for org.springframework.context.annotation.AnnotationConfigApplicationContext 
for information on code-based alternatives to bootstrapping annotation-driven support. 
     ]]></xsd:documentation> 
    </xsd:annotation> 
</xsd:element> 
+0

위대한 작품입니다. 감사! – alan

관련 문제