Results 1 to 4 of 4

Thread: Spring 2.0 final, Hibernate, Acegi, EhCache, proxying error

  1. #1
    Join Date
    Oct 2006
    Location
    London
    Posts
    19

    Default Spring 2.0 final, Hibernate, Acegi, EhCache, proxying error

    I am trying to finish upgrading my application to Hibernate-3.2ga and springframework-2.0 but I am stuck with a proxying problem.

    I need proxies setting up on the business service objects for transactions and security, and Hibernate needs to proxy the domain objects for database access and again for auditing.

    What baffles me is that I thought it must be Hibernate misbehaving because the upgrade was (mostly) working before I changed that, but it is a business object causing the problem (cardServiceCore - I included its definition below).

    These are the versions of some of the relevant jars I'm using:

    acegi-security-1.0.2
    aopalliance-1.0
    aspectjrt-1.5.2a
    aspectjweaver-1.5.2a
    cglib-2.1_3
    ehcache-1.2.3
    hibernate-3.2.0.ga
    ognl-2.6.9
    spring-aop-2.0
    spring-core-2.0
    spring-hibernate3-2.0

    Here's the config setting up the proxying:

    Code:
      <bean id="cardServiceCore"
        class="com.nomadsoft.cortex.domain.card.basic.BasicCardServiceCore">
        <constructor-arg index="0" ref="cardRepository" />
        <constructor-arg index="1" ref="cardStatusRepository" />
        <property name="securityServices" ref="securityServices" />
      </bean>
      <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
          <ref bean="sessionFactory" />
        </property>
      </bean>
      <aop:aspectj-autoproxy />
      <bean class="com.nomadsoft.cortex.infrastructure.ParameterLoggingAspect">
        <property name="order" value="2" />
      </bean>
      <bean id="methodSecurityInterceptor"
        class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
        <property name="authenticationManager">
          <ref bean="authenticationManager" />
        </property>
        <property name="accessDecisionManager">
          <ref local="businessAccessDecisionManager" />
        </property>
        <property name="objectDefinitionSource">
          <value>
               blah.blah.SecurityServices.*=xxxx
          </value>
        </property>
      </bean>
      <bean id="transactionInterceptor"
        class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager" ref="transactionManager" />
        <property name="transactionAttributes">
          <props>
            <prop key="get*">PROPAGATION_SUPPORTS,readOnly</prop>
            <prop key="persist*">PROPAGATION_REQUIRED</prop>
          </props>
        </property>
      </bean>
      <bean id="autoProxyCreator"
        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="interceptorNames">
          <list>
            <value>transactionInterceptor</value>
            <value>methodSecurityInterceptor</value>
          </list>
        </property>
        <property name="beanNames">
          <list>
            <value>*ServiceCore*</value>
          </list>
        </property>
        <property name="proxyTargetClass" value="true" />
        <property name="order" value="1" />
      </bean>


    Code:
    ERROR context.ContextLoader.initWebApplicationContext() - Context initialization failed 
    org.springframework.beans.factory.BeanCreationException:  
    Error creating bean with name 'cardServiceCore' defined in class path resource [applicationContext.xml]:  
    Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException:  
    Couldn't generate CGLIB subclass of class [class $Proxy6]:  
    Common causes of this problem include using a final class or a non-visible class;  
    nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy6 
    Caused by: 
    org.springframework.aop.framework.AopConfigException:  
    Couldn't generate CGLIB subclass of class [class $Proxy6]:  
    Common causes of this problem include using a final class or a non-visible class;  
    nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy6 
    Caused by: 
    java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy6 
    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446) 
    at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33) 
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) 
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216) 
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) 
    at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) 
    at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:202) 
    at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:147) 
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:72) 
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:392) 
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:249) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBea 
    nFactory.java:312) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1023) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348) 
    at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    You are using 2 transaction mechanisms at the same time

    Code:
    <aop:aspectj-autoproxy />
    and

    Code:
     
      <bean id="autoProxyCreator"
        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="interceptorNames">
          <list>
            <value>transactionInterceptor</value>
            <value>methodSecurityInterceptor</value>
          </list>
        </property>
        <property name="beanNames">
          <list>
            <value>*ServiceCore*</value>
          </list>
        </property>
        <property name="proxyTargetClass" value="true" />
        <property name="order" value="1" />
      </bean>
    Both are creating proxied objects and the first one doesn't automatically proxy the target class. Change it to the following, (from the reference guide page 128).

    Code:
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2006
    Location
    London
    Posts
    19

    Default

    Thanks Marten, that sorted it. I thought I had tried completely removing that logging aspect, but realised just now that I hadn't deployed the jar - dufus!

    Is there actually a way of writing this logging aspect as an interceptor? It would satisfy my sense of neatness to implement it that way and list it as a parameter to the autoProxyCreator.

    I don't like the idea of having that extra AOP framework floating around if I can do it another way.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Sure you can write it as an interceptor, although I'm not exactly sure what you are logging in your logging aspect. But I think it is definitly possible. Create an implementation of the MethodInterceptor and rewrite your code for the aspect and you should be good to go.

    You also might want to take a look at the TransactionInterceptor that already implements that interface.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •