Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler(WAB unable to locate spring context handlers)
ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler [message #910806] Mon, 10 September 2012 12:23 Go to next message
Seth Helstrip is currently offline Seth HelstripFriend
Messages: 22
Registered: September 2012
Junior Member
Really hoping someone can help me with this, it's had me stumped for days now...

I have a very simple, Spring MVC OSGi bundle. The MANIFEST.MF for this bundle looks like this;-

Manifest-Version: 1.0
Export-Package: com.learning-osgi.test.external;version="0.0.1.SNAPSHOT"
Bundle-ClassPath: .,WEB-INF/classes
Built-By: JJB
Tool: Bnd-1.50.0
Bundle-Name: spring-mvc-bundle
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.7.0_05
Bundle-Version: 0.0.1.SNAPSHOT
Bnd-LastModified: 1347278431206
Bundle-ManifestVersion: 2
Import-Package: com.learning-osgi.test.external,javax.servlet.http,org.eclip
 se.virgo.web.dm,org.springframework.context;version="[3.0,4)",org.spr
 ingframework.stereotype;version="[3.0,4)",org.springframework.validat
 ion;version="[3.0,4)",org.springframework.web.bind.annotation;version
 ="[3.0,4)",org.springframework.web.servlet;version="[3.0,4)"
Bundle-SymbolicName: com.learning-osgi.test.spring-mvc-bundle
Archiver-Version: Plexus Archiver



I'm deploying this bundle to the Eclipse Virgo server, and as such have included the
 org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext 
, within my web.xml, rather than the standard Spring XmlWebApplicationContext.

web.xml;-
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="necessary xsds">
	
	
 	<servlet>
		<servlet-name>mvc-dispatcher</servlet-name>
		<servlet-class>
         	org.springframework.web.servlet.DispatcherServlet
         </servlet-class>
         <load-on-startup>2</load-on-startup>

		<init-param>
			<param-name>contextClass</param-name>
			<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
			<!-- org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext -->
		</init-param>
		
		<load-on-startup>2</load-on-startup>
	</servlet>   
	
 	<context-param>
		<param-name>contextClass</param-name>                                                       
		<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
	</context-param>
 
	<servlet-mapping>
		<servlet-name>mvc-dispatcher</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
 

</web-app>


The bundle deploys successfully. However, when I try to hit the dispatcher servlet, I get the following exception;-

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is org.springframework.beans.FatalBeanException: NamespaceHandler class [org.springframework.context.config.ContextNamespaceHandler] for namespace [www.springframework.org/schema/context] not found; nested exception is java.lang.ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler not found from bundle [com.learning-osgi.test.spring-mvc-bundle]
	org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
	org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
	org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
	org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
	org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
	org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
	org.eclipse.gemini.blueprint.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:170)
	org.eclipse.gemini.blueprint.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:140)
	org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
	org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)...


Looking back at the MANIFEST.MF, there is an Import-Package to include the bundle,
org.springframework.context;version="[3.0,4)"


and checking on the Virgo server, this bundle exists. If I do a jar -tf on the jar, which contains this bundle, the missing class is there.

With all of this in mind, I'm completely stuck, to the point of having to consider walking away from OSGi for this project - which seems insane. I've searched around, and seen many other people having similar issues to this, but they're normally resolved by providing the necessary imports, etc.

I've attached my complete Maven3 project, in the hope that some kind soul will build it and tell me what's not right. I'm building the war this generates, and deploying it to a VANILLA install of Virgo Tomcat (3.5.0.RC1).

Can someone please help?

[Updated on: Mon, 10 September 2012 15:24]

Report message to a moderator

Re: ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler [message #911775 is a reply to message #910806] Wed, 12 September 2012 09:47 Go to previous messageGo to next message
Seth Helstrip is currently offline Seth HelstripFriend
Messages: 22
Registered: September 2012
Junior Member
Thought I'd post a reply on how I solved this, in the hope that it stops others making the same mistake.

The problem lies in the Import-Package being generated by the maven-bundle-plugin. Essentially what this plugin does is to scan the bundle classpath, identifying all classes used within the bundle, cross referencing this with the maven dependencies and generating the relavent Import-Package statement.

Because in this case, the jar was in fact a war, and as such contained XML that wasn't deemed as being on the classpath, the bundle plugin wasn't picking up the required dependencies. This went for both level 1 and transitive dependencies (I spotted the level 1 requirement).

The way I overcame this was to provide a dummy import for the 'missing' class within one of my Java files, and to see what the bundle plugin was adding to the import statement. I'd then run the war again, and a new classNotFoundException for a level 2 class was produced. Again, imported and used this within a java class, and eventually by following this pattern, was able to get the full Import-Package required, and as such add the necessary forced imports to the configuration of the bundle plugin.

For anyone having the same problem, and wanting to try a quick fix, this is what was added (to the plugin config - not the MANIFEST.MF).

<Import-Package>*,org.eclipse.virgo.web.dm,
org.springframework.context,
org.springframework.context.support,
org.springframework.context.config,
org.springframework.web.servlet.config,
org.springframework.web.servlet.view,
org.springframework.web.servlet.view.xml
</Import-Package>


I'm going to be publishing the much needed Maven 3 archetypes for Spring MVC bundles shortly, will update this thread with the location.

Hope this helps someone.

[Updated on: Wed, 12 September 2012 09:47]

Report message to a moderator

Re: ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler [message #916636 is a reply to message #911775] Wed, 19 September 2012 09:04 Go to previous messageGo to next message
Seth Helstrip is currently offline Seth HelstripFriend
Messages: 22
Registered: September 2012
Junior Member
Thought I'd improve this answer, since I might have misguided with my previous reply. Although that technique will work for you! The maven-bundle-plugin expects to find config files in the following location in your Maven project


/src/main/resource/META-INF/spring

So, if you place your spring config here, you'll find that it's able to locate the necessary dependencies, and you won't need to provide custom configuration for the Import-Package statement.

Hope this helps.
Re: ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler [message #925006 is a reply to message #916636] Thu, 27 September 2012 09:59 Go to previous messageGo to next message
Graeme Dougal is currently offline Graeme DougalFriend
Messages: 8
Registered: September 2012
Junior Member
Hi

I have a similar problem.. Have an osgi module set up and am trying to wire up my beans from different context files referenced by the module-context.xml file in src/main/resources/META-INF/spring

For example
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<import resource="encryptor-beans.xml"/>
<import resource="ds-beans.xml"/>
</beans>

The above context files are also located in src/main/resources/META-INF/spring

encryptor-beans.xml - wires up
- org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig
- org.jasypt.encryption.pbe.StandardPBEStringEncryptor

ds-beans.xml - wires up
- org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer
- org.springframework.jndi.JndiObjectFactoryBean

The MANIFEST.MF imports the jasypt bundle and encryptor-beans.xml wires up correctly with no issues. However when ds-beans.xml is wired up I get an exception stack trace

org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer] for bean with name 'ApplicationProperties' defined in OSGi resource[classpath:ds-beans.xml|bnd.id=153|bnd.sym=]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer not found from bundle

Caused by: java.lang.NoClassDefFoundError: org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer not found from bundle
Caused by: org.eclipse.virgo.kernel.osgi.framework.ExtendedNoClassDefFoundError: org/springframework/beans/factory/config/PropertyPlaceholderConfigurer in KernelBundleClassLoader
Caused by: org.eclipse.virgo.kernel.osgi.framework.ExtendedNoClassDefFoundError: org/springframework/beans/factory/config/PropertyPlaceholderConfigurer in KernelBundleClassLoader
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/PropertyPlaceholderConfigurer
Caused by: org.eclipse.virgo.kernel.osgi.framework.ExtendedClassNotFoundException: org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in KernelBundleClassLoader
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.PropertyPlaceholderConfigurer


I've added the import package for org.springframework.beans.factory.config in the MANIFEST but still always get the same error...

Any ideas ? (apologies for the long post)

Cheers
Graeme
Re: ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler [message #927560 is a reply to message #925006] Sat, 29 September 2012 20:16 Go to previous message
Benoit Lafleche is currently offline Benoit LaflecheFriend
Messages: 10
Registered: April 2011
Junior Member
Hi Graeme,

Which version of Jasypt are you using ? Is it the version 1.5.0 taken from the springsource bundle repository? If yes, then if you look at the manifest of this version, then their are the following 2 optional imports that could not be satisfied :

org.springframework.beans.factory.config     [2.5.4.A, 3.0.0) 	true
org.springframework.security.providers.encoding    [2.0.0.A, 3.0.0) 	true 


I have been trying to use it with Virgo 3.5.0 and I was getting the same class not found error even if my Jasyst bundle 1.5.0 was deployed succesfully.

If this is another bundle version that you were using, then where did you get it as I have been looking for a newer version that accept Spring 3.0.x and higher?

Benoit
Previous Topic:Virgo 3.6.0.M01 Released
Next Topic:Autowiring services >1 deep
Goto Forum:
  


Current Time: Fri Apr 26 20:19:10 GMT 2024

Powered by FUDForum. Page generated in 0.03490 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top