2010-12-27 9 views
8

में इंजेक्ट करने में असमर्थ वसंत मैं एक वस्तु के अंदर एक वस्तु को इंजेक्ट करने की कोशिश कर रहा हूं। लेकिन यह हमेशा शून्य हो जाता है। इस इंटरसेप्टर निम्नलिखित परिभाषावसंत

<context:load-time-weaver /> 
<context:component-scan base-package="framework.interceptor" /> 

@Aspect 
public class LoggingInterceptor { 
    @Autowired 
    EventLogManager eventLogManager; 
..... 
} 

मेरी इकाई परीक्षण कुछ इस तरह है, सिवाय इसके वसंत से का उपयोग कर AspectJ इसलिए कामयाब नहीं डोमेन वस्तुओं इंजेक्षन करने के लिए इस्तेमाल किया गया था। जब asa.execute() कहा जाता है तो इसे लॉगिंगइंटरसेप्टर द्वारा अवरुद्ध किया जाता है, लेकिन LoggingInterceptor.eventLogManager हमेशा शून्य होता है। लेकिन नीचे testInjection() ठीक काम करता है।

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = {  "classpath:applicationContext-dao.xml", 
            "classpath:applicationContext-service.xml", 
            "classpath:applicationContext-resources.xml", 
            "classpath:LoggingTest-context.xml"}) 
public class LoggingInterceptorTest { 

    @Autowired 
EventLogManager eventLogManager; 

@Test 
public void testInjection(){ 
    Assert.assertNotNull(eventLogManager); 
} 

@Test 
public void testAccountSaveActionAdvice(){ 
    AccountSaveAction asa = new AccountSaveAction(); 
    asa.execute(); 
} 
} 

मेरी applicationContext-service.xml इस

<aspectj> 
<weaver> 
    <!-- only weave classes in this package --> 
    <include within="action..*" /> 
</weaver> 
<aspects> 
    <!-- use only this aspect for weaving --> 
    <aspect name="interceptor.LoggingInterceptor" /> 
</aspects> 
</aspectj> 

उत्तर

3

कि काम नहीं किया की तरह दिखता है निम्नलिखित

<bean id="eventLogManager" 
    class="service.impl.EventLogDBManagerImpl"> 
    <property name="eventLoggingDao" ref="eventLoggingDao" /> 
</bean> 

मेरी META-INF में aop.xml है।

मैंने थोड़ी सी गुगल की और वसंत मंच बोर्ड में समाधान पाया। यहां लिंक

http://forum.springsource.org/showthread.php?t=79674