@Configurable-Beans not working with JPA-EntityListeners in Spring Boot -


i having strange problem custom jpa-entity listener i've created in spring boot application. i'm trying use springs @configurable mechanism configure entitylistener (as seen in springs auditingentitylistener) spring refuses recognize listener used in @entitylisteners-annotation on jpa entity. if not configured on jpa entity, listener gets wired/configured spring should.

i've created example project junit-test demonstrate problem: https://github.com/chrisi/aopconfig/find/master

@springbootapplication @enablespringconfigured @enableloadtimeweaving public class application {    public static void main(string[] args) throws exception {     springapplication.run(application.class, args);   } } 

the entitylistener:

/**  * bean not instanciated spring should configured spring  * because of {@link configurable}-annotation.  * <p>  * configuration works if <code>unmanagedbean</code> not used <code>entitylistener</code>  * via {@link javax.persistence.entitylisteners}-annotation.  *  * @see fooentity  */ @configurable public class unmanagedbean {    @autowired   private managedbean bean;    public int getvalue() {     return bean.getvalue();   } } 

the bean want injected in entitylistener/unmanagedbean:

/**  * bean instanciated/managed spring , injected  * {@link unmanagedbean} in case <code>unmanagedbean</code> not used jpa-entitylistener.  */ @component @data public class managedbean {   private int value = 42; } 

the entity listener should used:

/**  * simple entity's purpose demonstrate  * annotated <code>@entitylisteners({unmanagedbean.class})</code>  * springs configurable mechanism not longer work on {@link unmanagedbean}  * , therefore <code>configurabletest.testconfigureunmanagedbean()</code> fails.  */ @entity @entitylisteners({unmanagedbean.class}) // uncomment make test fail public class fooentity {    @id   private long id;    private string bar; } 

and test shows wiring not working listener used:

@runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = application.class) public class configurabletest {    /**    * test checks if managedbean injected unmanagedbean    * spring after created <code>new</code>    */   @test   public void testconfigureunmanagedbean() {     unmanagedbean edo = new unmanagedbean();     int val = edo.getvalue();     assert.assertequals(42, val);   } } 

the junit-test (the wiring of entitylistener/managedbean) fails annotation @entitylisteners({unmanagedbean.class}) in fooentity activated.

is bug or did miss else?

in order run test have use -javaagent:spring-instrument-4.1.6.release.jar on commandline provide jar file in working directory.

this "condensed" version of question asked earlier: @configurable not recognized in springboot application


Comments

Popular posts from this blog

What Are The Best Universities In The World?

The Ten Most Livable Cities In The World

Hard vs. Soft Water: What's The Difference?