spring - Injected bean reset to NULL in the Aspect -


i new spring aop , aspectj. have seen various posts related injected bean in aspect being null , have run similar problem. still not clear how should proceed past problem encountering.

issue: using spring 3.2.3 , injection through annotation. in case, dependent bean injected spring @ point of execution injected bean null. btw, doesn't happen time can stack trace when fails , when succeeds different. when injected bean not null (i can use injected bean service), call before advice (in aspect) happens before target method called should.when injected bean null, call aspect first statement of target method. @ point, think aspect instantiated , has no reference injected bean. here aspect have created:

@component @aspect public class enable{         private nameservice nameservice;         @autowired        public void setnameservice(nameserice service){                       // service injected             this.nameserice = service;        }         @before("* *.*(..)")              public void callbefore(joinpoint jp){                 //sometimes nameservice null , not not                 this.nameservice.lookup(...);            } } 

examining various posts, 1 way around (as suggested in post) configure aspect in xml configuration file , use factory-method ="aspectof" , in configuration inject reference nameservice bean property. our whole project uses annotation based injection (as stated earlier). assuming can still configure above aspect in xml configuration file, how can reference nameservice bean id can add configuration. saw post related using configurable annotation assume objects created outside spring ioc.

currently, aspects woven using aspectj compile option in pom.xml. our root-context.xml contains entry context:annotation-config , aspect injected spring ioc because component-scan turned on folder aspect resides. appreciated

this common error when use aspects in spring, should add

<context:spring-configured/>   

and

<aop:aspectj-autoproxy /> 

also add

@configurable @aspect public class enable 

to appcontext.xml

aspectof style above prefer use nature of context.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -