java - Spring AOP proxy doesn't work as expected -


actually i'am confused behavior of spring proxies. think know main difference between proxy mechanisms of j2ee, cglib , aspectj. have aspectj auto proxy enabled in configuration class , aspectj included in class path.

my configuration

@configuration @enableaspectjautoproxy(proxytargetclass = true) public class applicationconfiguration {     ... } 

aspectj dependency

<dependency>     <groupid>org.aspectj</groupid>     <artifactid>aspectjrt</artifactid>     <version>1.8.5</version> </dependency> 

by using simple setup i've assumed bean injection work intended. instead application results in illegalargumentexceptions messages "can not set [...] field [...] com.sun.proxy.$proxy30". means spring uses j2ee proxy service, aspectj proxy enabled.

finally i've figured out interfaces on service causes behavior. seems spring decides use j2ee proxy when service implements interface. if remove them, works.

failure:

@service @validated public class myservice implements interface1, interface2 {      @override     public void methodfrominterface1() {     }      @override     public void methodfrominterface2() {     }      public void servicemethod() {     } } 

ok:

@service @validated public class myservice {      public void methodfrominterface1() {     }      public void methodfrominterface2() {     }      public void servicemethod() {     } } 

until i've understand interfaces required j2ee proxy. it's new me, cglib/aspectj proxy doesn't work beans implements interfaces.

is there way to...

... force spring not use j2ee proxies?

... force spring use cglib/aspectj proxies (even classes have interfaces)?

is bug or desired behavior of spring?

edit: example updated, @transational replaced @validated

edit2: solution: @validated affected methodvalidationpostprocessor. property proxytargetclass has set true bean.

@bean public methodvalidationpostprocessor methodvalidationpostprocessor() {     final methodvalidationpostprocessor methodvalidationpostprocessor;     methodvalidationpostprocessor = new methodvalidationpostprocessor();     methodvalidationpostprocessor.setproxytargetclass(true);     return methodvalidationpostprocessor; } 

@enableaspectjautoproxy annotation applies @aspect annotations, not on @transactional annotations. that, need have @enabletransactionmanagement annotation on @configuration class, proxytargetclass = true attribute value.

@configuration @enableaspectjautoproxy(proxytargetclass = true) @enabletransactionmanagement(proxytargetclass = true) public class applicationconfiguration {     ... } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -