AOP advices in conjuction with TX
need a little mental help to get my brain oriented right with AOP/TX in spring....
recently ran into an error that popped up while using a service inside an AOP advice. namely that the service might not be initialized prior to injecting into the advice/pointcut (typical allowInit warning). the service is proxied as transactional by using the autoproxy on a transactionManager pairing up methods with transaction types. assuming AOP is used behind the scenes. and that when I define my AOP advice the order of which advice (the spring ready made transaction AOP and my own) is unknown.
to get around the problem i simply marked the service bean with lazy-init equal to true so that it is built only when needed. not at init time (i assume?).
wondering when using the TX advices with spring 2.0 if one can specify order precedence so the there isn't a conflict of when the service is made into a transactional bean? or am i off the deep end? assuming that the root cause of my origal error was due to unknown order in kicking off AOP advices (trans/my own).
guess i am looking for a general blueprint for how to configure transactional beans (services) and AOP advices acting on those services (beans).
thanks in advance / matthew
forgot to post the most important part (transaction)
forgot the most important configuration (namely the transaction advices):
management XML file
<!-- Hibernate TM (active in non-container) *installation parameter -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
<!--:Transaction attributes for Services -->
<bean id="transactionAttributes" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<!-- Transaction Interceptor for Services -->
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- AutoProxy for Services -->
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
suggestions for reworking
any suggestions for reworking the configuration?
thought at the Order interface might be the problem. but basically i want to apply business logic dynamically to the service without coding directly in the service implementation. ie. the extra logic that the advice adds against the service may not be necessary in 4/5 months so there is no point in adding it inside the service implementation.
This may be too little too late, but...here is what I found to be the problem when I
This may be too little too late, but...here is what I found to be the problem when I recieved this error....
(you know which error I mean):
I was matching the Interceptor itself when I received that error!
Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor': Cannot create inner bean '(inner bean)' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'loggerInterceptor' while setting bean property 'aspectBean'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'loggerInterceptor': Bean with name 'loggerInterceptor' has been injected into other beans [(inner bean)#2, (inner bean)#4] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
I believe there is another word for this, it is called Circlular Reference
Try placing the interceptor in a different package from the one you are matching. And DO NOT match it with a pointcut.
Andrew J. Leer