1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Ticket #92 (closed defect: fixed)

Opened 13 months ago

Last modified 10 months ago

Can't apply aop to beans created by factory

Reported by: d1rtym0nk3y Owned by: markmandel
Priority: major Milestone: Alpha2
Component: AOP Version: 2.0
Keywords: aop proxy factory Cc:

Description

Not sure if this is a bug, or a limitation (of my understanding)

Given this config

<!-- transactions via aop -->
<aop:config>

<aop:advisor advice-ref="transactionAdvice" pointcut="@annotation(transaction)" />

</aop:config>
<bean id="transactionAdvice" class="coldspring.transaction.interceptor.TransactionInterceptor?" />

<bean id="EntityServiceFactory?" class="model.entity.service.ServiceFactory?" />
<!-- these beans are both instances of model.entity.service.UserService? -->
<bean id="UserServiceDirect?" class="model.entity.service.UserService?" />
<bean id="UserServiceViaFactory?" factory-bean="EntityServiceFactory?" factory-method="getUserService" />

method calls marked @transaction on UserServiceDirect? work as expected, but are not executed within a transaction in UserServiceViaFactory?.

Inspecting the services after they're injected i can see that UserServiceDirect? has been proxied but that UserServiceViaFactory? is an untouched instance of UserService?.

Change History

Changed 13 months ago by markmandel

  • version set to 2.0
  • milestone set to Alpha2

This sounds like a valid bug, as the BeanPostProcessor? should pick up the factory created bean, I should have thought. I will look into it.

Changed 12 months ago by markmandel

  • owner set to markmandel
  • status changed from new to accepted

So this is both a bug, and an interesting bit of theory as well.

So basically, the bean created from the factory-method doesn't get called, because the auto proxying happens in the postProcessBeforeInstantiation event in the InstantiationAwareBeanPostProcessor.

Since CS doesn't manage the bean getting created, there is no way that event can get fired.

Spring manages this by checking the bean coming through the postProcessAfterInitialization event to see if it was handled previously and also if it wasn't - check to see if it needs to be proxied, and if so, wrap it the bean coming through with a proxy and return that instead.

So let's do that.

Changed 10 months ago by markmandel

  • status changed from accepted to closed
  • resolution set to fixed

Not sure why I didn't mark this as fixed. It was done ages ago.

Changed 10 months ago by markmandel

Note: See TracTickets for help on using tickets.