This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Injecting aspect into domain object

Sep 12th, 2007, 01:23 AM

Good day!

I want to introduce extra functionality (tags) into my domain (Account, Operation) object using aspect. So it would be possible to add tags and query for them, e.g. domain object would implement interface Taggable: addTag(), setTags(), getTags()....

When I have a bean in spring container then it works well (Account instance of Taggable == true), but if I create it using operator new() then it fails.

I also tried using @Configurable on domain object - it works well for injecting dependencies, but it does not introduce my advice.

testTagMixinBean() works well, but testTagMixinPojo() fails on assertTrue(account instanceof Taggable). It means that property "name" is set to necessary value, but aspect does not work for object created with new().

Class com.gb.account.model.CashAccount hase @Confugurable annotation, and interface com.gb.tags.aspect.Taggable and class com.gb.tags.aspect.TaggableImpl are just stubs, com.gb.tags.aspect.EntityTagging is an @Aspect.

Do you run your unittests from inside eclipse? I ask since I have had some problems with getting @Configured to work when running unittests inside eclipse, but I found some hints in the folowing thread witch made be sort out this issues:

Comment

Yes I do run tests from Eclipse, but to be sure that @Configurable works there's an assertion in each test: assertEquals("test", account.getName()) which checks that property (account.name) was set according to bean in application context.

The thing that does not work is: aspect (EntityTagging) is not introduced in domain object created with new().

By the way if I run tests from maven I get the same result.

Comment

Yes I do run tests from Eclipse, but to be sure that @Configurable works there's an assertion in each test: assertEquals("test", account.getName()) which checks that property (account.name) was set according to bean in application context.

The thing that does not work is: aspect (EntityTagging) is not introduced in domain object created with new().

By the way if I run tests from maven I get the same result.

I've got the same problem.
Using compiletime weaving - and the @Configurable stuff has been set (I assert it after instanciating with new as well ) - but the interceptors are never applied.

The classes I'm advising don't implement interfaces - does yours? (Although this shouldn't be a problem as I'm setting proxy-classes to true as well).

Probably a bug in spring.

I'm sure the pointcut definitions are OK as they match other beans defined with similar pointcuts (e.g. syntactically the same - but other packages.)

Have you registered a JIRA issue for this?

Comment

Hi, maybe it's a bug... but another thing is @Configurable maybe not intended to inject aspect, just dependencies... What I'm trying to do is to implement the same functionality - to have an aspect which should inject necessary aspects when creating domain object with new().

If you have any other ideas or suggestions I would gladly discuss them.

And how can I post a JIRA issue? (I'm new to it).

Thanks.

Comment

Hi, maybe it's a bug... but another thing is @Configurable maybe not intended to inject aspect, just dependencies... What I'm trying to do is to implement the same functionality - to have an aspect which should inject necessary aspects when creating domain object with new().

If you have any other ideas or suggestions I would gladly discuss them.

Comment

hey altosz,
Can you please tell me if you were able to resolve the issue. I am having the same issue. All injections are working fine in pojo, only the aspects arent getting applied. How to solve this.

Comment

That will be great. Thanks a lot. I am thinking that I am doing something very stupid cos I followed all the steps in spring documentation and yet couldnt get it to work. Anyways I will be waiting for your post.