【问题标题】:Using JAX-WS webservices with Spring 3.0.X on JBoss AS 7.1.X在 JBoss AS 7.1.X 上使用带有 Spring 3.0.X 的 JAX-WS Web 服务
【发布时间】:2012-05-13 19:54:10
【问题描述】:

我在 JBoss AS Final 7.1.1 上使用 Spring 3.0.6 部署 JAX-WS Web 服务时遇到一些问题。

我已经尝试了本教程中的两种第一种方法:http://www.javacodegeeks.com/2010/11/jaxws-with-spring-and-maven-tutorial.html

当我使用第一种方法(扩展 SpringBeanAutowiringSupport 并在 web.xml 中声明 servlet)时,应用程序正确部署,但我在 web 服务中注入的 bean 为 Null。

使用 SimpleJaxWsServiceExporter 的第二种方法我在部署时遇到错误:

10:09:33,012 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter#0' defined in ServletContext resource [/WEB-INF/generic-applicationContext.xml]: Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: java.lang.RuntimeException: java.net.BindException: Address already in use: bind
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_18]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_18]
    at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_18]
Caused by: javax.xml.ws.WebServiceException: java.lang.RuntimeException: java.net.BindException: Address already in use: bind
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:350)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:239)
    at org.jboss.wsf.stack.cxf.client.ProviderImpl$DelegateEndpointImpl.publish(ProviderImpl.java:300)
    at org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter.publishEndpoint(SimpleJaxWsServiceExporter.java:68) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.remoting.jaxws.AbstractJaxWsServiceExporter.publishEndpoints(AbstractJaxWsServiceExporter.java:154) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.remoting.jaxws.AbstractJaxWsServiceExporter.afterPropertiesSet(AbstractJaxWsServiceExporter.java:125) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    ... 20 more

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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

    <display-name>subscription-barring-service</display-name>

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

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

应用上下文:

<?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"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

        <context:component-scan
            base-package="org.bluewin.bwsso.services.barring" />

        <bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"/>
</beans>

网络服务:

@Service("terminateSessionsEndpoint") 
@WebService(serviceName = "TerminateSessionsEndpoint", portName = "TerminateSessionsEndpoint")
public class TerminateSessionsEndpoint extends SpringBeanAutowiringSupport {

    private Logger logger = Logger.getLogger(TerminateSessionsEndpoint.class);

    @Autowired
    Service serviceImpl;

    @WebMethod(operationName = "TerminateAllSessionsForAccountId")
    @WebResult(name = "TerminateAllSessionsResponse") 
    public TerminateAllSessionsResponseVO terminateAllSessionsForAccountId(
            @WebParam(name = "TerminateAllSessionsRequest") 
            TerminateAllSessionsRequestVO requestWS) {

        //do some logic..
    }
}

任何线索我怎样才能让它工作?

【问题讨论】:

  • 端口问题,需要检查可用端口
  • 不是端口问题。这是更困难的事情。当您更改 SimpleJaxWsServiceExporter 的端口时:&lt;property name="baseAddress" value="http://localhost:9999/ws/" /&gt; 它仍然给出相同的异常。我还尝试使用此方法配置它使用 JAX-WS 公开基于 servlet 的 Web 服务(static.springsource.org/spring/docs/3.1.x/…),然后 JBoss 上的部署没有任何问题,但是使用 @Autowired 注入的 bean不起作用。
  • 根据日志,与端口有关。
  • 一般认为,使用 JAX-WS 公开 WS 并不需要完全成熟的 Java EE 容器。

标签: spring jax-ws jboss7.x autowired


【解决方案1】:

我在部署具有类似配置的 JAX-WS 时也遇到了问题。实际上,使用 Spring 文档章节“19.5.5 使用 JAX-WS 公开基于 servlet 的 Web 服务”中描述的 SpringBeanAutowiringSupport 并不能按预期工作。

见文档http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#remoting-web-services

但是你在这里尝试使用 SimpleJaxWsServiceExporter 是错误的。 spring doc 的“19.5.6 使用 JAX-WS 导出独立 Web 服务”一章。

这与 jboss 已注册的 Web 服务发生冲突。

为了证明尝试使用更新的端口号进行以下配置 应用上下文:

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
   <property name="baseAddress" value="http://localhost:8081/"/>
</bean>

最终你将运行两个暴露的服务

http://localhost:8080/war-root/MyService?wsdl
http://localhost:8081/MyService?wsdl

目前我发现了其他人提出的两种解决方法:

  1. 使用 org.springframework.beans.factory.config.AutowireCapableBeanFactory:Jax-ws, spring and SpringBeanAutowiringSupport
  2. 将依赖注入移至@PostConstruct 方法:JBoss 6 + Spring 3.0.5 + JAX-WS/CXF

两种解决方法都可以正常工作。

【讨论】:

    【解决方案2】:

    这绝对是端口问题。例外很明显。

    Caused by: javax.xml.ws.WebServiceException: java.lang.RuntimeException: java.net.BindException: Address already in use: bind
    

    根据您的评论,您表示在端口 9999 &lt;property name="baseAddress" value="http://localhost:9999/ws/" /&gt; 上有监听。 management-native 默认端口是端口 9999。如果您在 &lt;socket-binding-group/&gt; 下查看 standalone.xml,您可能会看到类似以下内容。

    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
        <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
        <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
        <socket-binding name="ajp" port="8009"/>
        <socket-binding name="http" port="8080"/>
        <socket-binding name="https" port="8443"/>
        <socket-binding name="osgi-http" interface="management" port="8090"/>
        <socket-binding name="remoting" port="4447"/>
        <socket-binding name="txn-recovery-environment" port="4712"/>
        <socket-binding name="txn-status-manager" port="4713"/>
        <outbound-socket-binding name="mail-smtp">
            <remote-destination host="localhost" port="25"/>
        </outbound-socket-binding>
    </socket-binding-group>
    

    使用以下命令独立启动测试。

    $JBOSS_HOME/bin/standalone.sh -Djboss.management.native.port=19999
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-01
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      相关资源
      最近更新 更多