Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equinox(org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean#0': Invocation of init method faile)
Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equinox [message #815276] Wed, 07 March 2012 08:01 Go to next message
Nitin Kumar is currently offline Nitin Kumar
Messages: 7
Registered: March 2012
Junior Member
Description: I am starting a PoC using Spring MVC in an OSGi environment using Eclipse Gemini. I get the below error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equinox. Will appreciate any pointers.

Error: (full stack trace attached: 'equinox.txt') org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean#0': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: required property 'bundleContext' has not been set
..
..
ERROR org.springframework.web.context.ContextLoader - Context initialization failed
initWebApplicationContextjava.lang.IllegalArgumentException: bundle context should be set before refreshing the application context

Attachments:
1. Log file containing error: equinox.txt
2. equinox configuration file: config.ini
3. Spring MVC file: ch08-springmvc-1.0-SNAPSHOT.jar
4. Spring MVC dependency file: ch08-directory-1.0-SNAPSHOT.jar

I had downloaded the base config.ini and Java6-server.profile files as per instructions at www.eclipse.org/gemini/web/documentation/gemini-web-documentation-2.0.1.RELEASE/gemini-web-user-guide/html/ch02s02.html . Then I made some changes to the config.ini file for updating some of the jar versions and added some missing dependency jars. Java6-server.profile file was not changed.)

Please let me know should you need additional info.

Similar problem has been discussed at the below link. But I am already using Tomcat as part of gemini-web distribution:
forum.springsource.org/showthread.php?59911-bundle-context-should-be-set-before-refreshing-the-application-context

Many thanks in advance for any pointers.

Re: Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equ [message #815294 is a reply to message #815276] Wed, 07 March 2012 08:29 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
Have you considered using Virgo Tomcat Server (which includes Gemini Web) instead? It was designed to make the use of Spring with OSGi straightforward and you would then not have to re-invent that particular wheel.
Re: Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equ [message #815303 is a reply to message #815294] Wed, 07 March 2012 08:42 Go to previous messageGo to next message
Nitin Kumar is currently offline Nitin Kumar
Messages: 7
Registered: March 2012
Junior Member
Thanks for the pointer. I will give it a go with Virgo. Does Virgo follow 'OSGi inside Tomcat' model as opposed to 'Tomcat inside OSGi' model?

It would still be useful to understand the root cause of the above issue as I am just following a very simple example. Considering the fact that Gemini Blueprint and Gemini Web have originated from Spring DM, the current model (Tomcat embedded under OSGi) should also work.
Re: Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equ [message #815304 is a reply to message #815303] Wed, 07 March 2012 08:44 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
Virgo Tomcat Server embeds Tomcat inside OSGi. Gemini Web did not originate from Spring DM. The web side of Spring DM was a dead end and should be ignored.
Re: Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equ [message #815398 is a reply to message #815304] Wed, 07 March 2012 11:00 Go to previous messageGo to next message
Nitin Kumar is currently offline Nitin Kumar
Messages: 7
Registered: March 2012
Junior Member
Thanks again.
Re "The web side of Spring DM was a dead end and should be ignored."
- Spring MVC in an OSGi environment requires "org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext" in place of the standard 'XmlWebApplicationContext' which is used for 'non-OSGi Spring MVC'. The OsgiBundleXmlWebApplicationContext is provided by org.springframework.osgi.web-1.2.1 jar file. How do you suggest I ignore Spring DM then? Is there any other mechanism of providing applicationContect support for making Spring MVC application work inside OSGi environment? DO I continue to use XmlWebApplicationContext instead of OsgiBundleXmlWebApplicationContext?

- Should I ignore these jars as well:
a. org.springframework.osgi.web.extender-1.2.1.jar : Related to Spring DM Web and NOT present inside Virgo distribution
b. org.springframework.osgi.extensions.annotation-1.2.1.jar? : NOT related to Spring DM Web AND NOT present inside Virgo distribution


On a different note, the Spring MVC application fails with same error inside Virgo (ERROR Thread-34 0rg.springframework.web.context.ContextLoader Context initialization failed java.lang.IllegalArgumentException: bundle context should be set before refreshing the application context).

I have uploaded the log file from 'virgo-tomcat-server-3.0.2.RELEASE\serviceability\logs' folder.

I have also uploaded the source code (maven project) of the PoC Spring MVC application (ch08-web-springmvc.rar) for you to take a look at and suggest the changes required to make it inside Virgo. The 'target' folder has the binary version of the application. The binary version of the dependent application 'ch08-directory' has already been provided.

Please note that I have copied the following jars inside the 'pickup' directory inside Virgo home directory for meeting the dependencies of the Spring MVC application. The jars are installed and shown ACTIVE from the Virgo admin console.
org.springframework.osgi.extensions.annotation-1.2.1
org.springframework.osgi.web-1.2.1
org.springframework.web-3.0.5.RELEASE
org.springframework.web.servlet-3.0.5.RELEASE
org.springframework.osgi.web.extender-1.2.1 : My application doesn't seem to have any dependency on this JAR as it doesn't seem to matter if I keep it or remove it from the 'pickup' directory.

Thanks

[Updated on: Wed, 07 March 2012 12:05]

Report message to a moderator

Re: Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equ [message #816079 is a reply to message #815398] Thu, 08 March 2012 06:57 Go to previous messageGo to next message
Nitin Kumar is currently offline Nitin Kumar
Messages: 7
Registered: March 2012
Junior Member
Hi again
I managed to make some progress by referring to the 'Greenpages' sample provided by Virgo documentation. But I am still unable to run my application inside Virgo. From the logs (attached log.rar), I can see:
[2012-03-08 11:29:47.120] ERROR Thread-33 o.a.c.core.ContainerBase.[Catalina].[localhost].[/springmvc] Servlet /springmvc threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

Here is what I changed inside my Spring MVC web application:
1. Updated web.xml file for contextClass as org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext (Updated project source project attached: ch08-web-springmvc.rar)

2. Deployed Spring Web related jars from "virgo-tomcat-server-3.0.2.RELEASE\repository\ext" directory to "virgo-tomcat-server-3.0.2.RELEASE\pickup" directory as my applications dependencies were not being met without deploying these jars: org.springframework.web-3.0.5.RELEASE.jar, org.springframework.web.servlet-3.0.5.RELEASE.jar

3. Deployed additional dependency jars for my spring mvc application in the 'pickup' directory: org.springframework.osgi.extensions.annotation-1.2.1.jar, com.springsource.javax.servlet.jsp.jstl-1.2.0.v20110728.jar, com.springsource.org.apache.taglibs.standard-1.1.2.v20110517.jar

4. Updated pom.xml file to update <Import-Package> for: org.eclipse.virgo.web.dm;version="3.0.2"

I am now clear about the 'dead end' that you referred for Spring DM. I would appreciate your inputs to fix the above issue.
It seems like a class-loader issue. The 'org.springframework.web.servlet.DispatcherServlet' class is provided by the 'org.springframework.web.servlet-3.0.5.RELEASE.jar' file. I manually deployed this jar file in the 'pickup' directory. Not sure why the Virgo deployer for the Spring MVC web application is unable to find this class.

Once again, your help is much appreciated.

Thanks

Re: Error while deploying a simple Spring MVC application using Gemini Blueprint, Gemini Web and Equ [message #816190 is a reply to message #816079] Thu, 08 March 2012 09:39 Go to previous message
Nitin Kumar is currently offline Nitin Kumar
Messages: 7
Registered: March 2012
Junior Member
I was finally able to make the application work. Here are the lessons learned:

1. Root cause of "java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet" was missing Import >> org.springframework.web.servlet;version="3.0.5" >>> inside build.xml

2. Revised Step 2 from previous post: Deployed Spring Web related jars from "virgo-tomcat-server-3.0.2.RELEASE\repository\ext" directory to "virgo-tomcat-server-3.0.2.RELEASE\lib\kernel" directory as the later directory contains all other Spring jars.. Not sure if this is mandatory.
Will be glad if you can validate this.


3. Applied the fix as per: forum.springsource.org/showthread.php?90422-XML-Schema-errors >> I was also running into this issue.

4. Imported additional dependencies. Complete list inside build.xml of the attached ch08-web-springmvc.rar. (Uploaded revised rar for dependency bundle: ch08-directory.rar with fix as per step 3)

5. Noticed below in logs. It seems that the file name for ServerOsgiBundleXmlWebApplicationContext must be applicationContext.xml. Mine was 'osgi-context.xml'. Renamed the file accordingly. Modified web.xml accordingly for 'contextConfigLocation' param.
Will appreciate if you could confirm this behaviour and clarify if there is a way to configure the file name.

[2012-03-08 14:01:04.194] INFO http-bio-8080-exec-1 org.springframework.web.context.support.XmlWebApplicationContext Refreshing WebApplicationContext for namespace 'springmvc-servlet': startup date [Thu Mar 08 14:01:04 GMT 2012]; parent: ServerOsgiBundleXmlWebApplicationContext(bundle=com.manning.sdmia.ch08.springmvc, config=/WEB-INF/applicationContext.xml)
[2012-03-08 14:01:04.194] INFO http-bio-8080-exec-1 org.springframework.beans.factory.xml.XmlBeanDefinitionReader Loading XML bean definitions from ServletContext resource [/WEB-INF/springmvc-servlet.xml]

6. Fixed the ContactsController.java class to use @AutoWired annotation in place of @ServiceReference annotation. Modified springmvc-servlet.xml accordingly and then modified applicationContext.xml to include <osgi:reference..> for looking up the ContactService bean implementation provided by the dependency application 'ch08-directory'.

Re the original question: Why the whole setup doesn't work outside of Virgo, i.e. inside Gemini Blueprint and Gemini Web >> I believe that the answer lies in the right implementation (rather replacement) of Spring web application context: instead of 'OsgiBundleXmlWebApplicationContext' (as per Spring DM documentation) 'ServerOsgiBundleXmlWebApplicationContext' (provided by org.eclipse.virgo.web.dm-3.0.2.RELEASE.jar) should be used. I get a sense that using just this jar, the same application can be made to work inside Gemini.
Will appreciate any thoughts on this...
Thanks for your help.

Previous Topic:OSGI - SPRING DM - WEBLOGIC 12G
Next Topic:Issues with Upgrading Spring version due to osgi-extender
Goto Forum:
  


Current Time: Thu Apr 17 23:49:54 EDT 2014

Powered by FUDForum. Page generated in 0.02133 seconds