2016-09-22 2 views
0

Ich habe folgende Bean-XML und es wird in ApplicationConfiguration.java importiert und nur erstellt DbManager autowired in Test-Klasse, aber es wird immer Null. Kann jemand helfen.NULL-Wert auf Autowired-Objekt im Frühjahr erhalten

<?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:context="http://www.springframework.org/schema/context" 
     xmlns:cache="http://www.springframework.org/schema/cache" 
     xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-4.0.xsd 
      http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache.xsd"> 

    <bean id="dbManager" class="com.bandu.myfriendsbook.common.services.dbservices.dbmanager.impl.DbManagerImpl"> 

    </bean> 

    <bean id="dbManagers" class="java.util.ArrayList"> 
     <constructor-arg> 
      <list> 
       <ref bean="dbManager"/> 
      </list> 
     </constructor-arg> 
    </bean> 

</beans> 

und Konfiguration Java-Datei aufrufen Jetzt

@Configuration("applicationConfiguration") 
@EnableSpringConfigured 
@ComponentScan 
@EnableCaching(mode = AdviceMode.PROXY, proxyTargetClass = true) 
@EnableTransactionManagement(proxyTargetClass = true, mode = AdviceMode.PROXY) 
@ImportResource({"classpath:META-INF/app-spring-common-config.xml"}) 
public class ApplicationConfiguration extends CachingConfigurerSupport{ 

     //othere beans like datasource, cachemanager 
} 

nur Bohne in ApplicationTest.java aber es wird immer immer null.

@Component 
public class ApplicationTest { 

    @Autowired 
    private DbManagerImpl dbManager; 

    public Integer testQuery(){ 
     return dbManager.testQuery(); 
    } 
} 
+0

@ComponentScan ("mein.paket")? – degr

Antwort

2

Sie müssen @ComponentScan mit dem Parameter basePackages oder basePackagesClasses verwenden. Beispiel:

@ComponentScan(basePackages = {"com.example"}) 
0

hinzufügen <context:annotation-config/> ur XML-Datei @Autowired Anmerkung zu arbeiten.

Verwandte Themen