Error @Autowired Service in Virgo [message #786595] |
Mon, 30 January 2012 16:04 |
Gabriel Afonso Messages: 23 Registered: December 2011 |
Junior Member |
|
|
Hi, I have 2 bundles:
Bundle 1. Export a service. This is the code
services-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<!--<osgi:service interface="com.divux.onex.comunication.Login" ref="login"/> -->
<osgi:service id="comunicationTemplateService" interface="com.company.admin.templateone.inter.ComunicationTemplate" ref="comunicationTemplate"/>
</beans>
bundle-context-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.company.admin.templateone.impl" />
</beans>
I scan the package com.company.admin.templateone.impl because there are the Class:
@Component("comunicationTemplate")
public class ComunicationTemplateImpl implements ComunicationTemplate {
@Override
public String getName() {
return "TemplateOne";
}
}
Fine.
The Code of the WAB Service Consumer is this:
ApplicationContext.xml
....
<osgi:reference id="comunicationTemplate" interface="com.company.admin.templateone.inter.ComunicationTemplate"/>
company-servlet.xml
<context:component-scan base-package="com.company.admin.core.controller"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
And the class where I have the @Autowired is this:
@Controller
public class IndexController {
@Autowired
ComunicationTemplate comunicationTemplate;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String showIndex(HttpServletRequest request) {
return "index";
}
}
But when I go to the index page of the Consumer Web Bundle (WAB) the application show an error message:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.company.admin.templateone.inter.ComunicationTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:244)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.eclipse.virgo.web.tomcat.support.ApplicationNameTrackingValve.invoke(ApplicationNameTrackingValve.java:33)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:662)
[/code]
I'm using Virgo 3.0.2 Release. The service bundle provider export the package of the Interface and the WAB consumer import the same package.
Sorry for the long post, but I dont know what am I doind wrong. Why am I having this error?
Also this WAB is using Spring security and Snaps libraries.
[Updated on: Mon, 30 January 2012 16:10] Report message to a moderator
|
|
|
|
|
|
|
Re: Error @Autowired Service in Virgo [message #786750 is a reply to message #786739] |
Mon, 30 January 2012 19:35 |
Gabriel Afonso Messages: 23 Registered: December 2011 |
Junior Member |
|
|
Hi Dmitry,
That is not the problem. I have the service provider (A), snap Host(H) and a snap child bundle (C). C wants to consume a service from A. But when I declare <osgi:list id="comunicationTemplate" interface="com.company.admin.templateone.inter.ComunicationTemplate"/> in my ApplicationContext.xml to receive the service and autowired in an Object in a Class of C there is a problem, because the application doesn't find a bean for Autowired that object.
But when I put <osgi:list id="comunicationTemplate" interface="com.company.admin.templateone.inter.ComunicationTemplate"/> in ApplicationContext.xml of the Host this work fine. Why can't I consume a service from a Child??
[Updated on: Mon, 30 January 2012 19:45] Report message to a moderator
|
|
|
|
Re: Error @Autowired Service in Virgo [message #786777 is a reply to message #786763] |
Mon, 30 January 2012 20:09 |
Gabriel Afonso Messages: 23 Registered: December 2011 |
Junior Member |
|
|
this is mi web.xml child
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>template</display-name>
<!-- CONFIGURE A PARENT APPLICATION CONTEXT -->
<context-param>
<param-name>contextClass</param-name>
<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- DISPATCHER SERVLET CONFIG -->
<servlet>
<servlet-name>template</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>template</servlet-name>
<url-pattern>/web/*</url-pattern>
</servlet-mapping>
</web-app>
I don't what I need to change in web.xml child to load the applicationContext of child, not applicationContext of the Host
[Updated on: Mon, 30 January 2012 20:22] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04246 seconds