Spring 4.x 基于 CXF 的 web 服务配置 - WildFly 10.1
Spring 4.x based CXF web service configuration - WildFly 10.1
我们想将我们的 Spring 应用程序从 JBoss 7.1.1 迁移到 WildFly 10.1。我们使用基于 CXF 和 Spring 托管的 Web 服务,但在 WildFly 10.1 上我们无法配置这些服务。
我们尝试了两种方法。
当我们使用 WildFly 网络服务子系统时,网络服务会正确发布,但在 WS 实现中我们无法访问 spring 托管 bean。
当我们在jboss-deployment-structure.xml中排除webservices子系统时,在web.xml中配置CXFServlet,在[=52中配置jaxws:endpoint =] xml 配置文件日志显示服务创建没问题,但不是基于真正的实现。错误的服务名称、命名空间和地址。
使用的spring配置:
<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:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
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-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.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://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="testWs" implementor="ns.test.ws.impl.TestWsImpl"
address="/test">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
</beans>
日志内容:
18:31:11,783 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf-beans.xml]
18:31:12,177 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf/cxf.xml]
18:31:12,290 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf/cxf-extension-jaxws.xml]
18:31:12,455 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
(ServerService Thread Pool -- 58) Loading XML bean definitions from
class path resource [META-INF/cxf/cxf-servlet.xml]
18:31:12,960
INFO
[org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean]
(ServerService Thread Pool -- 58) Creating Service
{http://impl.ws.test.ns/}TestWsImplService from class
ns.test.ws.impl.TestWsImpl
WS 实现:
package ns.test.ws.impl;
import java.util.ArrayList;
import javax.jws.WebService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import ns.test.ws.api.TestWs;
import ns.test.ws.domain.ApplicationInfo;
import ns.test.ws.domain.ApplicationInfoRequest;
import ns.test.ws.domain.ApplicationInfoResultContainer;
import ns.test.ws.domain.CallContext;
import ns.test.ws.domain.ResultContext;
import ns.test.ws.domain.ResultMessage;
@WebService(name = "ApplicationInfoService", serviceName = "ApplicationInfoService", portName = "ApplicationInfoServicePort", endpointInterface = "ns.test.ws.api.TestWs", targetNamespace = "http://test.ns/")
@Transactional
public class TestWsImpl implements TestWs {
@SuppressWarnings("unused")
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestWsImpl.class);
@Autowired
private VersionInfo versionInfo;
public ApplicationInfoResultContainer test(CallContext callContext, ApplicationInfoRequest appInfoRequest) {
ApplicationInfo result = new ApplicationInfo();
result.setAppName(versionInfo.getAppName());
result.setAppVersion(versionInfo.getVersion());
ResultContext resultContext = new ResultContext();
resultContext.setCorrelationId("corrId");
resultContext.setHighestMessageSeverity("W");
resultContext.setMessageList(new ArrayList<ResultMessage>());
resultContext.getMessageList().add(new ResultMessage("code", "sev", "system", "message"));
return new ApplicationInfoResultContainer(result, resultContext);
}
}
我们做错了什么?我们应该如何配置 spring 应用程序?
使用的依赖项:
野蝇 10.1
CXF 3.1.6(WildFly 10.1 模块)
Spring4.3.7
我找到了解决方案。请参阅以下存储库中的示例代码。
我们想将我们的 Spring 应用程序从 JBoss 7.1.1 迁移到 WildFly 10.1。我们使用基于 CXF 和 Spring 托管的 Web 服务,但在 WildFly 10.1 上我们无法配置这些服务。
我们尝试了两种方法。
当我们使用 WildFly 网络服务子系统时,网络服务会正确发布,但在 WS 实现中我们无法访问 spring 托管 bean。
当我们在jboss-deployment-structure.xml中排除webservices子系统时,在web.xml中配置CXFServlet,在[=52中配置jaxws:endpoint =] xml 配置文件日志显示服务创建没问题,但不是基于真正的实现。错误的服务名称、命名空间和地址。
使用的spring配置:
<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:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
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-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.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://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="testWs" implementor="ns.test.ws.impl.TestWsImpl"
address="/test">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
</beans>
日志内容:
18:31:11,783 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 58) Loading XML bean definitions from class path resource [META-INF/cxf-beans.xml]
18:31:12,177 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 58) Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
18:31:12,290 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 58) Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-jaxws.xml]
18:31:12,455 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 58) Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]
18:31:12,960 INFO [org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean] (ServerService Thread Pool -- 58) Creating Service {http://impl.ws.test.ns/}TestWsImplService from class ns.test.ws.impl.TestWsImpl
WS 实现:
package ns.test.ws.impl;
import java.util.ArrayList;
import javax.jws.WebService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import ns.test.ws.api.TestWs;
import ns.test.ws.domain.ApplicationInfo;
import ns.test.ws.domain.ApplicationInfoRequest;
import ns.test.ws.domain.ApplicationInfoResultContainer;
import ns.test.ws.domain.CallContext;
import ns.test.ws.domain.ResultContext;
import ns.test.ws.domain.ResultMessage;
@WebService(name = "ApplicationInfoService", serviceName = "ApplicationInfoService", portName = "ApplicationInfoServicePort", endpointInterface = "ns.test.ws.api.TestWs", targetNamespace = "http://test.ns/")
@Transactional
public class TestWsImpl implements TestWs {
@SuppressWarnings("unused")
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestWsImpl.class);
@Autowired
private VersionInfo versionInfo;
public ApplicationInfoResultContainer test(CallContext callContext, ApplicationInfoRequest appInfoRequest) {
ApplicationInfo result = new ApplicationInfo();
result.setAppName(versionInfo.getAppName());
result.setAppVersion(versionInfo.getVersion());
ResultContext resultContext = new ResultContext();
resultContext.setCorrelationId("corrId");
resultContext.setHighestMessageSeverity("W");
resultContext.setMessageList(new ArrayList<ResultMessage>());
resultContext.getMessageList().add(new ResultMessage("code", "sev", "system", "message"));
return new ApplicationInfoResultContainer(result, resultContext);
}
}
我们做错了什么?我们应该如何配置 spring 应用程序?
使用的依赖项:
野蝇 10.1
CXF 3.1.6(WildFly 10.1 模块)
Spring4.3.7
我找到了解决方案。请参阅以下存储库中的示例代码。