Class loading issue for Spring XML tags within Eclipse

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Class loading issue for Spring XML tags within Eclipse

Steve Storey
Hi there,

Thanks for the RC3 release, however I've a small problem - I'm using the Spring Tool Suite (3.6.2 - with Spring 4.1.2) within Eclipse, and I have a classloading issue, where the Spring plugin marks the following XML with an error:

    <bean id="myService" class="com.example.ConcreteClass">
        <!-- Expose this via DWR -->
        <dwr:remote javascript="MyService"> <!-- MARKED AS ERROR -->
            <dwr:include method="doSomething" />
        </dwr:remote>
    </bean>

and the Eclipse log shows the following stack trace:

org.springframework.beans.FatalBeanException: Unable to create DWR bean creator for 'myService'.; nested exception is java.lang.ClassNotFoundException: com.example.ConcreteClass
    at org.directwebremoting.spring.namespace.RemoteDecorator.decorate(RemoteDecorator.java:59)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.decorate(NamespaceHandlerSupport.java:99)
    at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.decorate(DelegatingNamespaceHandlerResolver.java:190)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateIfRequired(BeanDefinitionParserDelegate.java:1461)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1448)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1428)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.processBeanDefinition(BeansConfig.java:1289)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:205)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1333)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:406)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:449)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.example.ConcreteClass
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:236)
    at org.directwebremoting.spring.namespace.RemoteDecorator.decorate(RemoteDecorator.java:55)
    ... 24 more

and in turn I believe this is because RemoteDecorator:55 does

            beanCreator.addPropertyValue("beanClass", ClassUtils.forName(beanClassName, getClass().getClassLoader()));

but in fact should be doing:

            beanCreator.addPropertyValue("beanClass", ClassUtils.forName(beanClassName, ClassUtils.getDefaultClassLoader()));

which works both when running the application, and within the IDE as well.

I can work around it by introducing a proxy bean as well (assuming I have an interface to expose), but I'd like not to have to do this:

    <bean id="myService" class="com.example.ConcreteClass" />
    <bean id="dwrMyService" class="org.springframework.aop.framework.ProxyFactoryBean"
        p:proxyInterfaces="com.example.ServiceInterface"
        p:target-ref="myService">
        <!-- Expose this via DWR -->
        <dwr:remote javascript="MyService">
            <dwr:include method="doSomething" />
        </dwr:remote>
    </bean>


I couldn't raise a bug in JIRA because the user registration form is broken for me (shows a page without styling, and which kinda implies it thinks I'm logged in already - e.g. a logout link)

Steve

--
Steve Storey

e: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Class loading issue for Spring XML tags within Eclipse

david@butterdev.com
Thanks for the report Steve.  This was a mistake I made attempting to fix:
https://directwebremoting.atlassian.net/browse/DWR-614

I have just checked some changes in that should resolve it.  If you want to give it a try that would be great.  Build 576 on Bamboo, http://ci.directwebremoting.org/bamboo/browse/DWRTRUNK-ALL-576/artifact.  I will push it out to Sonatypes OSS repo as well.

-David

On 11/14/2014 03:13 PM, Steve Storey wrote:
Hi there,

Thanks for the RC3 release, however I've a small problem - I'm using the Spring Tool Suite (3.6.2 - with Spring 4.1.2) within Eclipse, and I have a classloading issue, where the Spring plugin marks the following XML with an error:

    <bean id="myService" class="com.example.ConcreteClass">
        <!-- Expose this via DWR -->
        <dwr:remote javascript="MyService"> <!-- MARKED AS ERROR -->
            <dwr:include method="doSomething" />
        </dwr:remote>
    </bean>

and the Eclipse log shows the following stack trace:

org.springframework.beans.FatalBeanException: Unable to create DWR bean creator for 'myService'.; nested exception is java.lang.ClassNotFoundException: com.example.ConcreteClass
    at org.directwebremoting.spring.namespace.RemoteDecorator.decorate(RemoteDecorator.java:59)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.decorate(NamespaceHandlerSupport.java:99)
    at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.decorate(DelegatingNamespaceHandlerResolver.java:190)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateIfRequired(BeanDefinitionParserDelegate.java:1461)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1448)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1428)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.processBeanDefinition(BeansConfig.java:1289)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:205)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1333)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:406)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:449)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.example.ConcreteClass
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:236)
    at org.directwebremoting.spring.namespace.RemoteDecorator.decorate(RemoteDecorator.java:55)
    ... 24 more

and in turn I believe this is because RemoteDecorator:55 does

            beanCreator.addPropertyValue("beanClass", ClassUtils.forName(beanClassName, getClass().getClassLoader()));

but in fact should be doing:

            beanCreator.addPropertyValue("beanClass", ClassUtils.forName(beanClassName, ClassUtils.getDefaultClassLoader()));

which works both when running the application, and within the IDE as well.

I can work around it by introducing a proxy bean as well (assuming I have an interface to expose), but I'd like not to have to do this:

    <bean id="myService" class="com.example.ConcreteClass" />
    <bean id="dwrMyService" class="org.springframework.aop.framework.ProxyFactoryBean"
        p:proxyInterfaces="com.example.ServiceInterface"
        p:target-ref="myService">
        <!-- Expose this via DWR -->
        <dwr:remote javascript="MyService">
            <dwr:include method="doSomething" />
        </dwr:remote>
    </bean>


I couldn't raise a bug in JIRA because the user registration form is broken for me (shows a page without styling, and which kinda implies it thinks I'm logged in already - e.g. a logout link)

Steve

--
Steve Storey

e: [hidden email]