Spring @Autowired不适用于@WebService带注释的类 [英] Spring @Autowired is not working for @WebService annotated class
问题描述
在尝试自动装配时获取空指针。
Getting null pointer while trying to autowire.
创建Web应用程序并使用以下Web服务:
Creating a Web application and using following webservices:
WebServiceEndpoint.java
@WebService
@Component
public class ChannelMapWebServiceEndpoint {
@Autowired
ChannelMapWebService webservice;
public ChannelMapInfo4[] getMaps() throws RemoteException {
return this.webservice.getMaps();
}
}
ChannelMapsebserviceImpl.java
@Service
public class ChannelMapWebServiceImpl implements ChannelMapWebService {
public ChannelMapInfo4[] getMaps() throws RemoteException {
System.out.println("hi");
}
}
应用context.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: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">
<context:annotation-config />
<context:component-scan base-package="ccad" />
<context:component-scan base-package="channelmapwebservice" />
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>
我在尝试通过SoapUI进行连接时将自动连接的对象Web服务设置为null。
I am getting the autowired object webservice as null while trying to connect through SoapUI.
推荐答案
Spring不会实例化(和管理)为请求类提供服务的 ChannelMapWebServiceEndpoint
对象,这就是为什么Spring无法自动绑定任何依赖项的原因。
The ChannelMapWebServiceEndpoint
object serving your request class is not instantiated (and managed) by Spring, which is why Spring can't autowire any dependencies.
请参阅以下问题的可接受答案:
如何使@WebService Spring意识
See the accepted answer for this question: How to make an @WebService spring aware
这篇关于Spring @Autowired不适用于@WebService带注释的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!