弹簧@AutoWired始终为空



我正在尝试从程序上的另一个系统调用 SOAP 服务。我已经使用 WSDL 生成了wsimport命令所需的 java 类。

这是我的程序配置

网络.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
<display-name>PTDAM Promo Engine</display-name>
<description>Promo Engine using Elastic Search</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/cxf-servlet.xml</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>promoengine</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>


这是我的XML配置文件,我在其中存储了配置位置


更新:在下面添加了ESCreditRunner类作为bean,但仍然得到相同的错误

cxf-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd 
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/jaxrs 
http://cxf.apache.org/schemas/jaxrs.xsd 
http://cxf.apache.org/core 
http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws 
http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd">        
<!-- use this to enable @AutoWired -->
<context:annotation-config />
<context:component-scan base-package="ptdam.emoney.webservice.transactions" />
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- Client -->
<jaxws:client id="topupWebService"
serviceClass="ptdam.emoney.webservice.transactions.TopupWebService"
address="http://localhost:8080/ecash-core-engine-dev-mitigasi/services/emoneytopup"
<!-- Beans -->
<bean id="esCreditRunner" class="com.ptdam.promo.services.ESCreditRunner" />
/>      
</beans>


这是我如何使用@AutoWired,在testCall()方法上调用 SOAP 服务topupWebService..


ESCreditRunner.java

package ptdam.emoney.webservice.transactions;    
public class ESCreditRunner {
private File statusFile;
private Properties status;
private static final Logger logger = Logger.getLogger(ESCreditRunner.class);

@Autowired
private TopupWebService topupWebService;
public void setTopupWebService(TopupWebService topupWebService) {
this.topupWebService = topupWebService;
}
// testing 04/07/2017
public void testCall(){
topupWebService.echoTest("Luki");
}
}

当我运行testCall()方法时,我总是在topupWebService变量上得到NullPointerException。看起来没有正确注射。.

我在这里错过了什么?


更新:我制作了另一个线程作为该线程的延续。请在此处查看:)带端点的 Spring Web Service 与无端点

您应该在类ESCreditRunner上设置注释@Component

您可以尝试使用:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "cxf-servlet.xml")

如果您的 xml 不在类路径中,则可以使用classpath:**/cxf-servlet.xml

我已经在我的类上使用@Component解决了问题,并将@Autowired设置为从控制器级联调用的所有对象,或者在诸如弹簧 mvc @Autowired错误的设置中检查您的包 类型不满足的"必需"依赖项

相关内容

  • 没有找到相关文章

最新更新