View Full Version : @Controller annotation Scanning in MVC with OSGi
drubio
Jun 11th, 2008, 09:34 PM
Hi,
I am attempting to deploy a Spring MVC app with Spring/OSGi, but I can't get the annotated controller to be detected and create the bean.....
'Error creating bean with name 'urlMapper' defined in URL [bundle://49.0:0/WEB-INF/helloworld-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'helloWorldController' is defined'
I found this other post on issue, stating it doesn't work in Spring 2.5.3
groups.google.com/group/spring-osgi/browse_thread/thread/cf1fa802f846feac/b0f7483ea63b8f8e?lnk=gst#b0f7483ea63b8f8e[/url]
However, I am using Spring 2.5.4 and Spring-OSGi 1.1, inclusively this WAR and config work outside OSGi, but it doesn't seem to pick up annotations and create the bean in OSGi.
Is the scanning of the controller class attempted on the OSGi classpath ? Or is the embedded Tomcat trying to scan for the bean under /WEB-INF/lib or /WEB/classes ? I've tried both but haven't managed to get it to work.
Are there any special packages the OSGi manifest should contain in order to perform scanning on the MVC Controller ?
Or are controller annotations even supported in the latest versions ?
Thanks for any guidance on the issue.
Costin Leau
Jun 12th, 2008, 06:51 AM
Classpath scanning is supported in Spring DM 1.1 (fully since M2) and yes, you should use Spring 2.5.4 otherwise only @component scanning will work.
You can turn on logging if you'd like to get more information not just on Spring-DM but also Spring: this normally gives more insight on why scanning doesn't work.
drubio
Jun 13th, 2008, 10:09 PM
Costin,
Thanks for the suggestion..turned on logging and got rid of a few warnings, including javax.annotation...but I'm still getting a few strange warnings right up to when the MVC servlet descriptor gets loaded., like Weblogic, IBM and persistence classes, could these be influencing the scanning of the controller class ? ( Stack at the end ).
The scanning declaration I am using is like this:
<context:component-scan base-package="com.springosgi.web"/>
Is the standard Spring context the correct one ? Or is there something like <osgi:context...>
I have used this <context:> scanning declaration both inside the /WEB-INF/helloworld-servlet.xml ( which is the standard place for non-OSGi apps )...and also inside the /META-INF/spring/hellworld.xml descriptor were OSGi bootstrap's....what would be the correct place in an OSGi app for controller scanning ? I am still a little fuzzy on how the OSGi'fied Tomcat processing WAR files...
In any event still can't get the scanning to work, any insight or tip would be greatly appreciated.
[code]
18:49:29.072 [Timer-1] DEBUG o.s.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is EmptyTargetSource: no target class, static
18:49:29.087 [Timer-1] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [bundle://36.0:0/WEB-INF/helloworld-servlet.xml]
18:49:29.352 [Timer-1] DEBUG o.s.b.f.xml.DefaultDocumentLoader - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderFactoryImpl]
18:49:29.356 [Timer-1] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
18:49:29.358 [Timer-1] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loaded schema mappings: {}
18:49:29.360 [Timer-1] DEBUG o.s.o.e.i.support.NamespacePlugins - Trying to resolving entity for null|wspringframework.org/schema/beans/spring-beans.xsd
18:49:29.361 [Timer-1] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Found XML schema [wspringframework.org/schema/beans/spring-beans.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-2.5.xsd 18:49:29.361 [Timer-1] DEBUG o.s.o.e.i.support.NamespacePlugins - XML schema for null|wspringframework.org/schema/beans/spring-beans.xsd found inside Spring Beans (org.springframework.beans)
18:49:29.399 [Timer-1] DEBUG o.s.o.e.i.support.NamespacePlugins - Trying to resolving entity for null|/wspringframework.org/schema/context/spring-context-2.5.xsd 18:49:29.400 [Timer-1] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Found XML schema [wspringframework.org/schema/context/spring-context-2.5.xsd] in classpath: org/springframework/context/config/spring-context-2.5.xsd 18:49:29.401 [Timer-1] DEBUG o.s.o.e.i.support.NamespacePlugins - XML schema for null[wspringframework.org/schema/context/spring-context-2.5.xsd found inside Spring Context (org.springframework.context) 18:49:29.455 [Timer-1] DEBUG o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Loading bean definitions 18:49:29.456 [Timer-1] DEBUG o.s.b.f.x.DefaultNamespaceHandlerResolver - Loaded mappings [{}]
18:49:29.457 [Timer-1] DEBUG o.s.o.e.i.support.NamespacePlugins - Trying to resolving namespace handler for wpringframework.org/schema/context WARNING: *** Class 'weblogic.management.Helper' was not found. Bundle 36 does not import package 'weblogic.management', nor is the package exported by any other bundle or available from the system class loader. *** (java.lang.ClassNotFoundException: *** Class 'weblogic.management.Helper' was not found. Bundle 36 does not import package 'weblogic.management', nor is the package exported by any other bundle or available from the system class loader. ***) 18:49:29.488 [Timer-1] DEBUG org.springframework.util.ClassUtils - Class [weblogic.management.Helper] or one of its dependencies is not present: java.lang.ClassNotFoundException: weblogic.management.Helper not found from bundle [com.apress.springosgi.ch3.web]
WARNING: *** Class 'com.ibm.websphere.management.AdminServiceFactory' was not found. Bundle 36 does not import package 'com.ibm.websphere.management', nor is the package exported by any other bundle or available from the system class loader. *** (java.lang.ClassNotFoundException: *** Class 'com.ibm.websphere.management.AdminServiceFactory' was not found. Bundle 36 does not import package 'com.ibm.websphere.management', nor is the package exported by any other bundle or available from the system class loader. ***)
18:49:29.505 [Timer-1] DEBUG org.springframework.util.ClassUtils - Class [com.ibm.websphere.management.AdminServiceFactory] or one of its dependencies is not present: java.lang.ClassNotFoundException: com.ibm.websphere.management.AdminServiceFactory not found from bundle [com.apress.springosgi.ch3.web]
18:49:29.506 [Timer-1] DEBUG o.s.o.e.i.support.NamespacePlugins - Namespace handler for wspringframework.org/schema/context found inside Spring Context (org.springframework.context)
18:49:29.564 [Timer-1] DEBUG org.springframework.util.ClassUtils - Class [javax.persistence.EntityManagerFactory] or one of its dependencies is not present: java.lang.ClassNotFoundException: *** Class 'javax.persistence.EntityManagerFactory' was not found. Bundle 25 does not import package 'javax.persistence', nor is the package exported by any other bundle or available from the system class loader. ***
18:49:29.575 [Timer-1] DEBUG o.s.b.f.xml.XmlBeanDefinitionReader - Loaded 5 bean definitions from location pattern [/WEB-INF/helloworld-servlet.xml]
18:49:29.575 [Timer-1] INFO o.s.o.w.c.s.OsgiBundleXmlWebApplicationContext - Bean factory for application context [org.springframework.osgi.web.context.support.OsgiB undleXmlWebApplicationContext@12fb0af]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@166340c
[code]
Costin Leau
Jun 20th, 2008, 08:08 AM
The warnings are expected - the context checks the presence of some classes for extra functionality such as transaction manager or the like. The debug message are nothing to worry about. As for the component scanning, try to isolate the problem - I'm currently away but I know there are some messages that indicate the presence of component classes as they are being scanned.
Costin Leau
Jun 20th, 2008, 08:09 AM
And by the way, to properly quote codes, end the [ code ] tag with a [ /code ] ;). Thanks.
liareuper
Jun 25th, 2008, 04:42 AM
Hi there,
i have got a similar problem to the one above (I use Spring 2.5.4 and spring dm 1.1.0 m2) and tried to use the @Repository annotation for my DAOs and autowired my session factory. If i do so, i get the following error
...
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private org.hibernate.SessionFactory de.einsundeins.crmbacksys.dao.impl.MyDAOImpl.sessi onFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [org.hibernate.SessionFactory] is defined: Unsatisfied dependency of type [interface org.hibernate.SessionFactory]: expected at least 1 matching bean
at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor$AutowiredFieldElem ent.inject(AutowiredAnnotationBeanPostProcessor.ja va:435)
at org.springframework.beans.factory.annotation.Injec tionMetadata.injectFields(InjectionMetadata.java:1 05)
at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessAfterIn stantiation(AutowiredAnnotationBeanPostProcessor.j ava:240)
If i define a bean in the app. context (and skip the @Repository annotation) everything works fine. Has anyone an idea????
(first i thought that the DAO with the Repository annotation is created more then once but i'm not sure)
Thanks for your answers!
Costin Leau
Jun 26th, 2008, 03:59 AM
liareuper, please start your own thread - your problem might be similar but in the end it's different (different setup, environment and so on).
What is your configuration and what are the beans available in your application context. Also what is your bundle classpath/structure?
Let's continue the discussion on a new thread.
Thanks,
liareuper
Jun 26th, 2008, 05:03 AM
Hi,
thanks for your answer. I started a new Thread called "AT Repository Annotation does not work"
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.