Announcement Announcement Module
Collapse
No announcement yet.
Transaction proxy on class with no default constructor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction proxy on class with no default constructor

    I'm trying to proxy a class using the TransactionProxyFactoryBean but the class does not have a default constructor. I'm getting the error below.

    I am using Spring 1.2 RC1.

    Does anyone have any tips? There was a similar discussion at http://opensource.atlassian.com/proj...browse/SPR-285 which talked about a solution but did not explain it.

    2005-04-15 09:49:40,700 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext-common-business.xml]: Initialization of bean failed; nested exception is org.aopalliance.aop.AspectException: null
    java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
    at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhan cer.java:682)
    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer .java:494)
    at net.sf.cglib.transform.TransformingClassGenerator. generateClass(TransformingClassGenerator.java:33)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:215)
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer. java:373)
    at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:2 81)
    at org.springframework.aop.framework.Cglib2AopProxy.g etProxy(Cglib2AopProxy.java:194)
    at org.springframework.aop.framework.Cglib2AopProxy.g etProxy(Cglib2AopProxy.java:150)
    at org.springframework.aop.framework.ProxyFactory.get Proxy(ProxyFactory.java:66)
    at org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean.afterPropertiesSet(Transacti onProxyFactoryBean.java:275)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1075)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:349)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:257)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:146)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:285)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
    at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:131)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:224)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:150)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 48)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3631)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4065)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:755)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:886)
    at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:849)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)

    at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1079)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1011)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1003)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:437)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2010)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:537)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:271)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:409)

    2005-04-15 09:49:40,716 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/CareerManager]] - Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext-common-business.xml]: Initialization of bean failed; nested exception is org.aopalliance.aop.AspectException: null
    java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
    at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhan cer.java:682)
    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer .java:494)
    at net.sf.cglib.transform.TransformingClassGenerator. generateClass(TransformingClassGenerator.java:33)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:215)
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer. java:373)
    at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:2 81)
    at org.springframework.aop.framework.Cglib2AopProxy.g etProxy(Cglib2AopProxy.java:194)
    at org.springframework.aop.framework.Cglib2AopProxy.g etProxy(Cglib2AopProxy.java:150)
    at org.springframework.aop.framework.ProxyFactory.get Proxy(ProxyFactory.java:66)
    at org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean.afterPropertiesSet(Transacti onProxyFactoryBean.java:275)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1075)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:349)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:257)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:146)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:285)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
    at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:131)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:224)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:150)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 48)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3631)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4065)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:755)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:886)
    at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:849)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)
    at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1079)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1011)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1003)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:437)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2010)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:537)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:271)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:409)

    Code:
        <bean id="userServiceTarget" class="com.bennettsworld.careermanager.services.UserService">
            <constructor-arg><ref local="userDao"/></constructor-arg>
        </bean>
    
    	<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager"><ref local="transactionManager"/></property>
            <property name="target"><ref local="userServiceTarget"/></property>
            <property name="transactionAttributes">
                <props>
                    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="add*">PROPAGATION_REQUIRED</prop>
                    <prop key="create*">PROPAGATION_REQUIRED</prop>
                    <prop key="delete*">PROPAGATION_REQUIRED</prop>
                    <prop key="save*">PROPAGATION_REQUIRED</prop>
                    <prop key="load*">PROPAGATION_REQUIRED</prop>
                    <prop key="store*">PROPAGATION_REQUIRED</prop>
                    <prop key="update*">PROPAGATION_REQUIRED</prop>
                    <prop key="set*">PROPAGATION_REQUIRED</prop>
                    <prop key="remove*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>

  • #2
    Transaction proxy on class with no default constructor

    I figured this out. All I had to do was create an interface for my service object (the one that needed declarative transaction management). Then in the target use the concrete implementation. I'll show the new spring configuration file below.

    I hope this helps somebody out there if you run into the same issue that I did. I should have created an interface for the service object anyway because that is a "best practice".

    Code:
        <bean id="userServiceTarget" class="com.bennettsworld.careermanager.services.UserServiceImpl">
            <constructor-arg><ref local="userDao"/></constructor-arg>
        </bean>
    
    	<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager"><ref local="transactionManager"/></property>
            <property name="target"><ref local="userServiceTarget"/></property>
            <property name="transactionAttributes">
                <props>
                    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="add*">PROPAGATION_REQUIRED</prop>
                    <prop key="create*">PROPAGATION_REQUIRED</prop>
                    <prop key="delete*">PROPAGATION_REQUIRED</prop>
                    <prop key="save*">PROPAGATION_REQUIRED</prop>
                    <prop key="load*">PROPAGATION_REQUIRED</prop>
                    <prop key="store*">PROPAGATION_REQUIRED</prop>
                    <prop key="update*">PROPAGATION_REQUIRED</prop>
                    <prop key="set*">PROPAGATION_REQUIRED</prop>
                    <prop key="remove*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>

    Comment

    Working...
    X