我已经在我的服务器项目中使用 Jax-ws 实现了一个 WS,并且我正在从客户端应用程序调用该服务。问题是,如果我想在 @WebService 带注释的类中使用 @Autowire,它总是会引发以下错误:
InjectionException:为类创建托管对象时出错:类 com.myco.wsserver.LeaveRequestEndPoint;
如果我调试该类,则对我的自动装配 bean 的引用为空。如果我从我的 @webservice 注释类中删除 bean 它可以工作,如果我手动获取应用程序上下文然后获取 bean 它也可以工作,但我想知道为什么我不能自动装配任何 bean。
这是我的代码。
网络服务类:
@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();
}
}
应用上下文:
<?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>