gpt4 book ai didi

JBossWS 中的 Spring 配置

转载 作者:行者123 更新时间:2023-12-03 23:06:41 26 4
gpt4 key购买 nike

我正在尝试使用 JBossWS( native 堆栈)公开 Web 服务,并利用 Spring 的依赖注入(inject)。这是我的代码的精简版本:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<display-name>Test Service</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>EndpointService</servlet-name>
<servlet-class>com.blah.webservice.EndpointService</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EndpointService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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:spring-configured />
<context:load-time-weaver />
<context:annotation-config />

<context:component-scan base-package="com.blah.webservice" />
</beans>

端点服务.java

package com.blah.webservice;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@WebService
@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE)
public class EndpointService {

private TestService testService;

public EndpointService() {}

@Autowired
public EndpointService(TestService testService) {
this.testService = testService;
}

@WebMethod
public String endpointEcho(String echo) {
return echo;
}

@WebMethod
public String serviceEcho(String echo) {
return testService.serviceEcho(echo);
}
}

测试服务.java:

package com.blah.webservice;

import org.springframework.stereotype.Service;

@Service
public class TestService {

public TestService() {}

public String serviceEcho(String echo) {
return echo;
}
}

当我构建它并部署到 JBoss 时,它启动得很好,我可以看到 Spring 正在预实例化我的类,但是当我发出对 Web 服务的调用时,endpointEcho 按预期工作,而 serviceEcho 抛出 NullPointerException。似乎当 JBossWS 实例化端点类时,它没有发现我的 Spring 配置。有没有一种简单的方法可以让 JBossWS 了解 Spring?我觉得我要么遗漏了一些非常小的细节,要么我完全错误地处理了这件事。有什么想法吗?

最佳答案

您的服务必须扩展 SpringBeanAutowiringSupport 才能利用 Autowiring 支持。

关于JBossWS 中的 Spring 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5304102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com