PDA

View Full Version : JtaTransactionManager depends on aopalliance.jar?



timmorrow
Sep 3rd, 2004, 05:31 PM
Not really a problem, I was just suprised to get the following error when using JtaTransactionManager programmatically with the following bean defintion (I only had spring.jar in my classpath):

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransaction Manager" />

The error was:


org.springframework.beans.factory.BeanDefinitionSt oreException&#58; Error registering bean with name 'transactionManager' defined in class path resource &#91;com/somepackage/ApplicationContext.xml&#93;&#58; Class that bean class &#91;org.springframework.transaction.jta.JtaTransactio nManager&#93; depends on not found; nested exception is java.lang.NoClassDefFoundError&#58; org/aopalliance/aop/AspectException
java.lang.NoClassDefFoundError&#58; org/aopalliance/aop/AspectException
at java.lang.Class.forName0&#40;Native Method&#41;
at java.lang.Class.forName&#40;Class.java&#58;219&#41;
at org.springframework.beans.factory.support.BeanDefi nitionReaderUtils.createBeanDefinition&#40;BeanDefinit ionReaderUtils.java&#58;50&#41;
...


I added aopalliance.jar to my classpath and it took care of the problem. Is it expected that this is a required dependency? Is it generally accepted that we should add all the supporting libs to the classpath, or just add them piecemeal as dependencies show themselves through errors like this?

Cheers,

Tim

Loumeister
Sep 3rd, 2004, 11:53 PM
I pretty much add them as needed due to the fact that we don't implement the whole spring framework. Like you, I needed to add the aopalliance.jar to use the interceptors, but that's been it so far.

Best,
Lou

irbouho
Sep 4th, 2004, 07:34 AM
Loumeister & Loumeister,

To implement Transaction using AOP, TransactionProxyFactoryBean uses internaly a TransactionInterceptor. the later extends TransactionAspectSupport that has a method readObject used for serialization.


private void readObject&#40;ObjectInputStream ois&#41; throws IOException &#123;
// Rely on default serialization, just initialize state after deserialization
try &#123;
ois.defaultReadObject&#40;&#41;;
&#125;
catch &#40;ClassNotFoundException ex&#41; &#123;
throw new AspectException&#40;"Failed to deserialize Spring AOP transaction aspect&#58;" +
"Check that Spring AOP libraries are available on the client side", ex&#41;;
&#125;

// Initialize transient fields
this.logger = LogFactory.getLog&#40;getClass&#40;&#41;&#41;;
&#125;

Throwing a AspectException makes transaction management in Spring depends on aopalliance.jar.
I think this should be documented somewhere in Spring documentation and readme.txt (http://cvs.sourceforge.net/viewcvs.py/springframework/spring/lib/readme.txt?view=markup) (spring libraries dependencies)

Juergen Hoeller
Sep 4th, 2004, 07:35 AM
In general, you need aopalliance.jar when working with Spring's AOP framework, whether directly or indirectly. However, JtaTransactionManager shouldn't depend on AOP Alliance: That has to be considered a bug. I've just fixed it: It was just an accidental use of the AOP Alliance AspectException that was straightforward to be replace.

Juergen

irbouho
Sep 4th, 2004, 07:59 AM
Oups, I am sorry for the confusion, I was looking at two many classes in the same times.
indeed, JtaTransactionManager has a readObject method:


private void readObject&#40;ObjectInputStream ois&#41; throws IOException &#123;
// rely on default serialization, just initialize state after deserialization
try &#123;
ois.defaultReadObject&#40;&#41;;
&#125;
catch &#40;ClassNotFoundException ex&#41; &#123;
throw new AspectException&#40;"Failed to deserialize JtaTransactionManager&#58; " +
"Check that JTA and Spring transaction libraries are available on the client side", ex&#41;;
&#125;
// do client-side JNDI lookup
this.jndiTemplate = new JndiTemplate&#40;&#41;;
// run lookup code for UserTransaction
this.userTransaction = lookupUserTransaction&#40;this.userTransactionName&#41;;
&#125;

that depends on aopapplicane.jar

Rod Johnson
Sep 7th, 2004, 01:08 AM
Sorry--my fault. Juergen's now fixed it for 1.1 final. Thanks for the feedback!

timmorrow
Sep 7th, 2004, 12:22 PM
Now that's great service!

Cheers,

Tim