Announcement Announcement Module
Collapse
No announcement yet.
JtaTransactionManager depends on aopalliance.jar? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JtaTransactionManager depends on aopalliance.jar?

    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.JtaTran sactionManager" />

    The error was:
    Code:
    org.springframework.beans.factory.BeanDefinitionStoreException&#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.JtaTransactionManager&#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.BeanDefinitionReaderUtils.createBeanDefinition&#40;BeanDefinitionReaderUtils.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

  • #2
    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

    Comment


    • #3
      Loumeister & Loumeister,

      To implement Transaction using AOP, TransactionProxyFactoryBean uses internaly a TransactionInterceptor. the later extends TransactionAspectSupport that has a method readObject used for serialization.
      Code:
      	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 (spring libraries dependencies)

      Comment


      • #4
        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

        Comment


        • #5
          Oups, I am sorry for the confusion, I was looking at two many classes in the same times.
          indeed, JtaTransactionManager has a readObject method:
          Code:
          	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

          Comment


          • #6
            Sorry--my fault. Juergen's now fixed it for 1.1 final. Thanks for the feedback!

            Comment


            • #7
              Now that's great service!

              Cheers,

              Tim

              Comment

              Working...
              X