Tuesday, 10 September 2013

Autowired in WS not working Spring

Autowired in WS not working Spring

I have implemented a WS using Jax-ws in my server project and I'm making
the calls to the service from a client application. The problem is that if
I want to use @Autowire inside my @WebService annotated class it always
throws the following error:
InjectionException: Error creating managed object for class: class
com.myco.wsserver.LeaveRequestEndPoint;
if I debug that class, the reference to my autowired bean is null. if I
remove the bean from my @webservice annotated class it works , also if I
get the application context manually and then get the bean it also works,
but I would like to know why I can't Autowire any bean.
Here is my code.
WebService class:
@WebService(serviceName="LeaveRequestHandler")
public class LeaveRequestEndPoint extends SpringBeanAutowiringSupport{
@Autowired
GenericBean mBean;
public LeaveRequestEndPoint(GenericBean mBean){
this.mBean = mBean;
}
@WebMethod(operationName="executeOperation")
public String getText() {
return mBean.getText();
}
}
application context:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:annotation-config />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp
resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="genericBean" class="com.myco.wsserver.GenericBean"/>
</beans:beans>

No comments:

Post a Comment