spring aop - java - @Aspect value attribute - Prototype scoped aspect bean -


i trying create aspect using spring aop , aspectj.

@aspect(value = "perthis(execution(* x.y.z.command.command.execute()))") public class commandadvice {       // advices.... } 

the javadoc 'value attibute says:-

per clause expression, defaults singleton aspect. valid values "" (singleton), "perthis(...)", etc 

everything works file without specifying 'value' attribute in @aspect annotation.

using above perthis setting resulted in following exception:-

caused by: java.lang.illegalargumentexception: bean name 'commandaspect' singleton, aspect instantiation model not singleton. 

so tried changing scope of advice bean prototype:-

<bean id="commandaspect" class="x.y.z.command.commandadvice" **scope="prototype"**     factory-method="aspectof" /> 

this resulted in :-

caused by: java.lang.illegalargumentexception: can not set x.y.z.command.command field x.y.z.test.commandtest.command sun.proxy.$proxy30 @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:146) @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:150) @ sun.reflect.unsafeobjectfieldaccessorimpl.set(unsafeobjectfieldaccessorimpl.java:63) @ java.lang.reflect.field.set(field.java:657) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:502) 

my requirement create 'prototype' scoped aspect bean.

  • is prototype aspect bean advisable? pros , cons in multi-threaded environment?

  • how using 'value' attribute?


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -