Announcement Announcement Module
Collapse
No announcement yet.
IllegalArgumentException when using ThreadLocalTargetSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IllegalArgumentException when using ThreadLocalTargetSource

    Hi,
    I am using a bean with a ThreadLocalTargetSource to get a different instance per thread. Here's my code:
    Code:
    	<bean id="myBean" class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="targetSource">
    			<ref local="myBeanThreadLocalTargetSource"/>
    		</property>
    		<property  name="target">
    			<ref local="myBeanTarget"/>
    		</property>
    	</bean>
    
    	<bean id="myBeanThreadLocalTargetSource" class="org.springframework.aop.target.ThreadLocalTargetSource" destroy-method="destroy"/>
    
    	<bean id="myBeanTarget" class="myBeanClass" singleton="false"/>
    I am getting the following exception when starting Spring :
    Code:
    &#91;org.springframework.web.context.ContextLoader&#93; - Context initialization failed
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean wit
    h name 'myBeanThreadLocalTargetSource' defined in ServletContext resource
     &#91;/WEB-INF/applicationContext-service.xml&#93;&#58; Initialization of bean failed; neste
    d exception is java.lang.IllegalArgumentException&#58; Cannot get bean with null nam
    e
    java.lang.IllegalArgumentException&#58; Cannot get bean with null name
            at org.springframework.beans.factory.BeanFactoryUtils.transformedBeanNam
    e&#40;BeanFactoryUtils.java&#58;51&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.transfo
    rmedBeanName&#40;AbstractBeanFactory.java&#58;655&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.isSingl
    eton&#40;AbstractBeanFactory.java&#58;280&#41;
            at org.springframework.aop.target.AbstractPrototypeBasedTargetSource.set
    BeanFactory&#40;AbstractPrototypeBasedTargetSource.java&#58;91&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;301&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;223&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
    &#40;AbstractBeanFactory.java&#58;236&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
    &#40;AbstractBeanFactory.java&#58;159&#41;
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.
    preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;261&#41;
            at org.springframework.context.support.AbstractApplicationContext.refres
    h&#40;AbstractApplicationContext.java&#58;317&#41;
            at org.springframework.web.context.support.AbstractRefreshableWebApplica
    tionContext.refresh&#40;AbstractRefreshableWebApplicationContext.java&#58;131&#41;
            at org.springframework.web.context.ContextLoader.createWebApplicationCon
    text&#40;ContextLoader.java&#58;177&#41;
            at org.springframework.web.context.ContextLoader.initWebApplicationConte
    xt&#40;ContextLoader.java&#58;105&#41;
            at org.springframework.web.context.ContextLoaderListener.contextInitiali
    zed&#40;ContextLoaderListener.java&#58;48&#41;
            at org.apache.catalina.core.StandardContext.listenerStart&#40;StandardContex
    t.java&#58;3831&#41;
            at org.apache.catalina.core.StandardContext.start&#40;StandardContext.java&#58;4
    323&#41;
            at org.apache.catalina.core.ContainerBase.addChildInternal&#40;ContainerBase
    .java&#58;823&#41;
            at org.apache.catalina.core.ContainerBase.addChild&#40;ContainerBase.java&#58;80
    7&#41;
            at org.apache.catalina.core.StandardHost.addChild&#40;StandardHost.java&#58;595&#41;
    
            at org.apache.catalina.core.StandardHostDeployer.addChild&#40;StandardHostDe
    ployer.java&#58;903&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.
    java&#58;39&#41;
            at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAcces
    sorImpl.java&#58;25&#41;
            at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
            at org.apache.commons.beanutils.MethodUtils.invokeMethod&#40;MethodUtils.jav
    a&#58;216&#41;
            at org.apache.commons.digester.SetNextRule.end&#40;SetNextRule.java&#58;256&#41;
            at org.apache.commons.digester.Rule.end&#40;Rule.java&#58;276&#41;
            at org.apache.commons.digester.Digester.endElement&#40;Digester.java&#58;1058&#41;
            at org.apache.catalina.util.CatalinaDigester.endElement&#40;CatalinaDigester
    .java&#58;76&#41;
            at org.apache.xerces.parsers.AbstractSAXParser.endElement&#40;Unknown Source
    &#41;
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement&#40;
    Unknown Source&#41;
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
    Dispatcher.dispatch&#40;Unknown Source&#41;
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument&#40;Un
    known Source&#41;
            at org.apache.xerces.parsers.XML11Configuration.parse&#40;Unknown Source&#41;
            at org.apache.xerces.parsers.XML11Configuration.parse&#40;Unknown Source&#41;
            at org.apache.xerces.parsers.XMLParser.parse&#40;Unknown Source&#41;
            at org.apache.xerces.parsers.AbstractSAXParser.parse&#40;Unknown Source&#41;
            at org.apache.commons.digester.Digester.parse&#40;Digester.java&#58;1567&#41;
            at org.apache.catalina.core.StandardHostDeployer.install&#40;StandardHostDep
    loyer.java&#58;488&#41;
            at org.apache.catalina.core.StandardHost.install&#40;StandardHost.java&#58;863&#41;
            at org.apache.catalina.startup.HostConfig.deployDescriptors&#40;HostConfig.j
    ava&#58;483&#41;
            at org.apache.catalina.startup.HostConfig.deployApps&#40;HostConfig.java&#58;427
    &#41;
            at org.apache.catalina.startup.HostConfig.start&#40;HostConfig.java&#58;983&#41;
            at org.apache.catalina.startup.HostConfig.lifecycleEvent&#40;HostConfig.java
    &#58;349&#41;
            at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent&#40;Lifecycl
    eSupport.java&#58;119&#41;
            at org.apache.catalina.core.ContainerBase.start&#40;ContainerBase.java&#58;1091&#41;
    
            at org.apache.catalina.core.StandardHost.start&#40;StandardHost.java&#58;789&#41;
            at org.apache.catalina.core.ContainerBase.start&#40;ContainerBase.java&#58;1083&#41;
    
            at org.apache.catalina.core.StandardEngine.start&#40;StandardEngine.java&#58;478
    &#41;
            at org.apache.catalina.core.StandardService.start&#40;StandardService.java&#58;4
    80&#41;
            at org.apache.catalina.core.StandardServer.start&#40;StandardServer.java&#58;231
    3&#41;
            at org.apache.catalina.startup.Catalina.start&#40;Catalina.java&#58;556&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
            at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.
    java&#58;39&#41;
            at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAcces
    sorImpl.java&#58;25&#41;
            at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
            at org.apache.catalina.startup.Bootstrap.start&#40;Bootstrap.java&#58;287&#41;
            at org.apache.catalina.startup.Bootstrap.main&#40;Bootstrap.java&#58;425&#41;
    Actually, this exception occurs when I merely declare a bean of type ThreadLocalTargetSource in my config file.
    Your help will be appreciated!

  • #2
    You need to specify a value for the targetBeanName property of the ThreadLocalTargetSource bean.

    Rob

    Comment

    Working...
    X