Classes not visible to OSGified Spring - spring

I am making a very simple app in which I try to init a spring bean using osgi (apache felix). I manage to read the spring-beans.xml file I include in the bundle with code like that:
ApplicationContext springContext = new GenericApplicationContext();
InputStream in = thisBundle.getEntry("/spring-beans.xml").openStream();
DefaultListableBeanFactory beans = new DefaultListableBeanFactory(springContext);
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beans);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
reader.loadBeanDefinitions(new InputStreamResource(in));
beans.preInstantiateSingletons();
in.close();
return springContext;
Where this is the content of the spring-beans.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="crazyClass" class="foo.bar.osgi.SpringInstantiatedBean">
<property name="name" value="YES" />
</bean>
</beans>
The SpringInstantiatedBean class has only one prop (name) and a getter/setter for it. This is all fine if I run it locally through a main class, although the path for locating the spring-beans.xml file is a bit different. However, when I do put this code on felix, here is what I get in my Activator:
Jun 7, 2012 4:37:40 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from resource loaded through InputStream
Jun 7, 2012 4:37:41 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#2778c490: defining beans [crazyClass]; root of factory hierarchy
org.osgi.framework.BundleException: Activator start error in bundle foo.bar.osgi.OSGIProject [91].
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2027)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)
at org.apache.felix.gogo.command.Basic.start(Basic.java:729)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
at org.apache.felix.gogo.shell.Console.run(Console.java:62)
at org.apache.felix.gogo.shell.Shell.console(Shell.java:203)
at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
at org.apache.felix.gogo.shell.Activator.run(Activator.java:75)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [foo.bar.osgi.SpringInstantiatedBean] for bean with name 'crazyClass' defined in resource loaded through InputStream; nested exception is java.lang.ClassNotFoundException: foo.bar.osgi.SpringInstantiatedBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:897)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:566)
at foo.bar.osgi.Activator.readSpringConfigAndInitContext(Activator.java:54)
at foo.bar.osgi.Activator.start(Activator.java:29)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:641)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977)
... 32 more
Caused by: java.lang.ClassNotFoundException: foo.bar.osgi.SpringInstantiatedBean
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:417)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1283)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254)
... 40 more
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [foo.bar.osgi.SpringInstantiatedBean] for bean with name 'crazyClass' defined in resource loaded through InputStream; nested exception is java.lang.ClassNotFoundException: foo.bar.osgi.SpringInstantiatedBean
The full stack trace just shows to me that at the moment of resolving the beans, spring internals can't find my bean class, which is weird because I can instantiate it in my Activator with no problem, like that:
SpringInitializedBean bean = new SpringInitializedBean();
This only suggests it is a classloader problem but is it possible that the classloader for the BeanFactory can't access my classes? If so, how do I make it see my classes? In addition, here is an excerpt of my pom.xml where I configure the maven bundle plugin:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.2.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>foo.bar.osgi.Activator</Bundle-Activator>
<Export-Package>foo.bar.osgi.osgi*</Export-Package>
<Private-Package>foo.bar.osgi*</Private-Package>
<Import-Package>*</Import-Package>
<Include-Resource>src/main/resources/spring-beans.xml</Include-Resource>
</instructions>
</configuration>
</plugin>

Your problem seems to be that Spring tries to load the bean using Class.forName or similar methods. It assumes that the class is visible from the system classloader. Due to the fact that OSGi has strong separation of classes with separate classloaders for each bundle, this assumption is not true.
Where is BeanFactory located? Is it in the system classpath of the OSGi framework, or is it packaged as a bundle itself?
If it is in a bundle, you can try playing with the Import-Package: and Export-Package clauses in the manifests of the two bundles as a temporary solution.

Two cheap things to try to get some clarity:
Use a Dynamic Import It's a bit of a last resort, effectively bypassing modular classloading, but it will tell you if this is indeed your problem.
Try it in Equinox instead of Felix. Felix is a bit more strict than Equinox. I know that Spring and Equinox work fine in Virgo. Again, in itself this won't solve your problem, but it will narrow things down a bit.

Related

ClassNotFoundException after upgrading from Spring 3.0.5 to 3.2.1 in RCP application

I have an RCP application with several hundred bundles that is wired with Spring dm. After upgrading to Spring 3.2.1, I now get the following exception in a couple of bundles. At first I thought it may be caused by some magic in dm, but after testing that theory by initializing the bundle without dm (simply starting up an ApplicationContext programatically), I still faced the same exception.
Stacktrace:
Exception in thread "SpringOsgiExtenderThread-130" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FileSystemsStackViewControlFactory' defined in OSGi resource[classpath:spring/filesystem-ui.xml|bnd.id=176|bnd.sym=filesystem.ui]: Instantiation of bean failed; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1011)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at org.springframework.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy$CglibSubclassCreator.instantiate(CglibSubclassingInstantiationStrategy.java:117)
at org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy.instantiateWithMethodInjection(CglibSubclassingInstantiationStrategy.java:69)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:91)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
... 15 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 21 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/cglib/proxy/Factory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
... 26 more
Caused by: java.lang.ClassNotFoundException: org.springframework.cglib.proxy.Factory
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 29 more
The original manifest was a mixture of Require-Bundle and Package-Import, so I tried removing the Require-Bundle altogether. Didn't expect this to change anything, but desperate times call for desperate measures, and I was right, still nothing.
As a last resort, I also tried adding this attribute, still no change.
DynamicImport-Package: *
I know that Spring changed their usage of cglib around version 3.1 to embed cglib and asm within their core jars, but I have included imports for all the cglib and asm packages to no avail.
Manifest:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: File System UI
Bundle-SymbolicName: com.mycorp.filesystem.ui;singleton:=true
Bundle-Version: 15.7.0.qualifier
Bundle-Activator: com.mycorp.filesystem.ui.internal.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: com.mycorpcse.utils.eclipse,
com.mycorp.common.ui,
:
Many other in house dependencies
:
com.mycorp.core,
org.eclipse.core.commands,
:
Many other eclipse dependencies
:
org.eclipse.ui.views.properties,
org.osgi.framework;version="1.7.0",
org.springframework.asm;version="3.2.1.RELEASE",
org.springframework.asm.commons;version="3.2.1.RELEASE",
org.springframework.asm.signature;version="3.2.1.RELEASE",
org.springframework.asm.util;version="3.2.1.RELEASE",
org.springframework.beans;version="3.0.5.RELEASE",
org.springframework.beans.factory.annotation,
org.springframework.cglib;version="3.2.1.RELEASE",
org.springframework.cglib.beans;version="3.2.1.RELEASE",
org.springframework.cglib.core;version="3.2.1.RELEASE",
org.springframework.cglib.proxy;version="3.2.1.RELEASE",
org.springframework.cglib.reflect;version="3.2.1.RELEASE",
org.springframework.cglib.transform;version="3.2.1.RELEASE",
org.springframework.cglib.transform.impl;version="3.2.1.RELEASE",
org.springframework.cglib.util;version="3.2.1.RELEASE"
Export-Package: com.mycorp.filesystem.ui,
com.mycorp.filesystem.ui.columns,
com.mycorp.filesystem.ui.model
Update: I now realize that this particular case is caused only when using lookup method injection. As I still don't know how to fix it, I have had to alter the config to not use this feature.
We solved a similar problem by adding import-package of org.springframework.cglib etc. to the org.springframework.transaction bundle.
It seems in Spring 3.2 they changed the internal class structure. With the default OSGI package those clib classes can not be found. Therefore you have to explicit specify in the MANIFEST.MF that you need those packages loaded in the context.
You can edit the MANIFEST.MF file in your jar file. In Import-Package section add the following 3 packages:
'org.springframework.cglib.core','org.springframework.cglib.proxy','org.springframework.beans.factory'
Or if you are using gradle you can do the following (assuming you have osgi plugin enabled already)
jar {
manifest {
instruction 'Import-Package', 'org.springframework.cglib.core', 'org.springframework.cglib.proxy', 'org.springframework.beans.factory', '*'
}
}

Trouble with class loading webapp JARs with Jetty 6

I have a Jetty 6.1.9 environment which I am trying to bootstrap an 'exploded' WAR style context, however, I am getting NoClassDefFoundError errors.
The Jetty env is bootstrapped like so:
public class MyServer {
public static void main(String[] argv) {
jetty_default = jetty_default + "/web-content/jetty-6.1.9";
String jetty_home = System.getProperty("jetty.home", jetty_default);
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(7895);
server.setConnectors(new Connector[]{connector});
WebAppContext myAppCxt= new WebAppContext();
myAppCxt.setContextPath("/foo");
myAppCxt.setWar(jetty_home + "/wardirs/myApp");
myAppCxt.setDefaultsDescriptor(jetty_home + "/etc/webdefault.xml");
myAppCxt.setInitParams(initParamsMaps);
myAppCxt.setTempDirectory(aTmpDir);
server.setHandler(processingNodeAppCxt);
server.start();
}
The layout of wardirs/myApp looks like so
wardirs
myApp
WEB-INF
lib\
jdom.jar
web.xml
The class I am getting the error for is in foo.jar.
It also feels like Jetty is finding the JAR in the WEB-INF/lib dir because after starting the server foo.jar becomes locked (I tried deleting it) and when I kill the server it becomes unlocked.
If I manually put the JARs on the classpath of the java cmd line which runs MyServer's main method then all works fine, however, I want these JARs to live in the WEB-INF\lib dir and be automatically picked up as they should be.
The actual exception is:
Mar 06, 2013 9:07:25 PM sun.reflect.NativeMethodAccessorImpl invoke0
SEVERE: /foo/api/process
java.lang.NoClassDefFoundError: org/jdom/Content
at com.foo.MyManager$Status.createICProcessor(MyManager.java:231)
at com.foo.myApp.Api.process(API.java:xxx)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:149)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
Caused by: java.lang.ClassNotFoundException: org.jdom.Content
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 35 more
The only other thing I can think to mention since this feels like a classloader context issue is that the MyManager referenced in the top line of the stack trace is running in its own thread which was started by the webapp's ServletContextListener like so:
myMgrThread = new Thread(myManager);
long myMgrThreadId = myMgrThread.getId();
myMgrThread .setName("MyApp_MyMgr-" + myMgrThreadId);
myMgrThread .setPriority(Thread.NORM_PRIORITY);
myMgrThread .setDaemon(true);
myMgrThread .start();
According to your project layout, and that stacktrace, it found com.foo.myApp.Api and com.foo.MyManager in your WEB-INF/lib/foo.jar just fine, but it failed to find org.jdom.Content
Is org.jdom.Content present in your wEB-INF/lib/foo.jar? or in a similar file you haven't mentioned like WEB-INF/lib/jdom.jar? Or are you expecting to find org.jdom.Content from the parent classloader (in other words, whatever classloader the MyServer class was started from)?
I think I answered my own question. The IDE project this is running in does not move the 'webapp' .class files into "$jetty_home/wardirs/myApp/WEB-INF/classes" as one would expect per the servlet spec. Instead it includes them in the class path which invokes MyServer.main.
When I copied the application classes into "$jetty_home/wardirs/myApp/WEB-INF/classes" the NOCLASSDEFERRORs went away. So now the classes are WEB-INF/classes and on the classpath calling main.
As you might be able to tell here this project has no separation of concerns between the webapp and the container. All the classes and JARS for the application and jetty have been dumped together and it 'works'. I've been trying to teases things apart so that the webapp classes and dependent JARs are clearly separated, eg. introducing a ServletContextListener to move webapp code into which was previously being bootstrapped from 'main', moving JARs into WEB-INF/lib and the like. It's like trying to get chewing gum out of your hair.

JBoss AS 7 upgrade to Java 7, JBoss VFS

We have an spring application which dynamically loads components based in the lib folder.
This application needs to be deployed on different AS, like Jetty,Tomcat,JBoss..
Now, JBoss has this VFS feature, where it does not really unpack your war it seems, and uses vfs:// for files inside the war/jar..
Currently we are in the process of upgrading (from Java6) to Java7, and we encounter the following problem.
First of all, snowdrop 1.0.0GA no longer works under Java7, because the InputStream was changed somehow.. Upgrading to snowdrop 2.0.4.Final resolved this issue.
Next up is this gem of a stacktrace:
11:37:44,563 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/runtime]] (MSC service thread 1-1) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from "/C:/Tools/jboss-as-7.1.1.Final/bin/content/Aquima-Server-9-SNAPSHOT.war/WEB-INF/classes/aquima-config.xml"; nested exception is java.lang.RuntimeException: java.lang.IllegalArgumentException: Null path
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
.....................
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Null path
at org.jboss.spring.vfs.VFSServletContextResourcePatternResolver.convertClassLoaderURL(VFSServletContextResourcePatternResolver.java:62) [snowdrop-vfs-2.0.4.Final.jar:2.0.4.Final]
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findAllClassPathResources(PathMatchingResourcePatternResolver.java:305) [spring-core-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:270) [spring-core-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1245) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
.........................
Caused by: java.lang.IllegalArgumentException: Null path
at org.jboss.vfs.VFS.getChild(VFS.java:187) [jboss-vfs-3.1.0.Final.jar:3.1.0.Final]
at org.jboss.vfs.VFS.getChild(VFS.java:173) [jboss-vfs-3.1.0.Final.jar:3.1.0.Final]
at org.jboss.vfs.VFS.getChild(VFS.java:154) [jboss-vfs-3.1.0.Final.jar:3.1.0.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_11]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_11]
at org.jboss.spring.vfs.VFSUtil.invokeMethodWithExpectedExceptionType(VFSUtil.java:157) [snowdrop-vfs-2.0.4.Final.jar:2.0.4.Final]
at org.jboss.spring.vfs.VFSUtil.invokeVfsMethod(VFSUtil.java:170) [snowdrop-vfs-2.0.4.Final.jar:2.0.4.Final]
at org.jboss.spring.vfs.VFSServletContextResourcePatternResolver.convertClassLoaderURL(VFSServletContextResourcePatternResolver.java:59) [snowdrop-vfs-2.0.4.Final.jar:2.0.4.Final]
... 34 more
Does anyone know how to resolve this?

Moved to Spring 3.1.1 from Spring 3.0.5 now my App does not work

Moved to Spring 3.1.1 from Spring 3.0.5 now my App does not work can someone please tell me what is up? I removed all the 3.0.5 jars and added the 3.1.1 jars
2012-05-14 12:01:41,195 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.context.ApplicationContextException: Couldn't locate: org.springframework.ldap.core.support.BaseLdapPathContextSource. If you are using LDAP with Spring Security, please ensure that you include the spring-ldap jar file in your application; nested exception is java.lang.ClassNotFoundException: org.springframework.ldap.core.support.BaseLdapPathContextSource
at org.springframework.security.config.ldap.ContextSourceSettingPostProcessor.postProcessBeanFactory(ContextSourceSettingPostProcessor.java:34)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:664)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.springframework.ldap.core.support.BaseLdapPathContextSource
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:258)
at org.springframework.security.config.ldap.ContextSourceSettingPostProcessor.postProcessBeanFactory(ContextSourceSettingPostProcessor.java:32)
... 21 more
May 14, 2012 12:01:41 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.context.ApplicationContextException: Couldn't locate: org.springframework.ldap.core.support.BaseLdapPathContextSource. If you are using LDAP with Spring Security, please ensure that you include the spring-ldap jar file in your application; nested exception is java.lang.ClassNotFoundException: org.springframework.ldap.core.support.BaseLdapPathContextSource
at org.springframework.security.config.ldap.ContextSourceSettingPostProcessor.postProcessBeanFactory(ContextSourceSettingPostProcessor.java:34)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
Have you done what it suggests and verified that spring-ldap is included with your app? That's clearly where the class in question lives. My guess is that you blindly removed all the jars named spring-* and added in all the 3.1 spring-* jar files, but spring-ldap isn't included with the base spring 3.1 distro. In fact, its versioning is completely separate, and it's presently at version 1.3.1.

maven test class files are not getting loaded: NoClassDefFoundError

I am getting following error while running junit test file with maven:
Caused
by:java.lang.NoClassDefFoundError:IllegalName:com/home/app/LoginDetailsTest
all my test class files are located at target\ test-classes and java class files are located at target\ classes directory.
since LoginDetailsTest located at target\ test-classes, it couldnot identify class files. how to solve this error?
spring xml file:
<bean id="loginDetails" class="com/home/app/LoginDetailsTest">
<property name="loginDetailsService" ref="loginService" />
</bean>
I am running junit test file through eclipse by right click and run as junit test.
<error message="Cannot find class [/com/home/app/LoginDetailsTest] for bean with name &apos;loginDetails&apos; defined in class path resource [com/home/app/LoginDetails-ctx.xml]; nested exception is java.lang.ClassNotFoundException: /com/home/app/LoginDetailsTest" type="org.springframework.beans.factory.CannotLoadBeanClassException">org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [/com/home/app/LoginDetailsTest] for bean with name &apos;loginDetails&apos; defined in class path resource [com/home/app/LoginDetails-ctx.xml]; nested exception is java.lang.ClassNotFoundException: /com/home/app/LoginDetailsTest
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:885)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.home.app.LoginDetailsTest.testLoginDetails(LoginDetailsTest.java:27)
Caused by: java.lang.ClassNotFoundException: /com/home/app/LoginDetailsTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
at org.springframework.bea
You have to give the class name this way in Spring : "com.home.app.LoginDetailsTest", not this way "com/home/app/LoginDetailsTest"

Resources