创建名为'messageDispatcher'

时间:2018-04-03 08:29:08

标签: java web-services spring-mvc

我在JAVA中创建了一个Web服务。每当我在eclipse和tomcat服务器中执行项目时,也会显示以下错误。我尝试了很多方法,但每次都有同样的错误。我没有清楚地看到这个问题。我在这里发布了我的代码。

堆栈跟踪

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageDispatcher' defined in ServletContext resource [/WEB-INF/mvc-ws-integration.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor#2': Cannot create inner bean 'org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor#0' of type [org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor#0' defined in ServletContext resource [/WEB-INF/spring-ws.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.ws.security.WSSecurityEngine.getInstance()Lorg/apache/ws/security/WSSecurityEngine;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

的web.xml

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

  <servlet>
      <servlet-name>spring</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
      <servlet-name>spring</servlet-name>
     <url-pattern>/</url-pattern>
  </servlet-mapping>
<servlet>
    <servlet-name>spring-ws</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
        <param-name>transformWsdlLocations</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring-ws</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

MVC-WS-integration.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:p="http://www.springframework.org/schema/p" 
            xmlns:sws="http://www.springframework.org/schema/web-services"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:oxm="http://www.springframework.org/schema/oxm"
            xsi:schemaLocation=
                "http://www.springframework.org/schema/beans 
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/web-services
                http://www.springframework.org/schema/web-services/web-services-2.0.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.1.xsd
                http://www.springframework.org/schema/oxm 
                http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">

<!-- SAAJ-specific implementation of the WebServiceMessageFactory. Wraps a SAAJ MessageFactory. 
This factory will use SAAJ 1.3 when found, or fall back to SAAJ 1.2 or even 1.1. -->
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>

<!-- Requires a message factory so we declare one -->
<bean class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter"
        p:messageFactory-ref="messageFactory"/>

<!--  See reference at the beginning of this document -->
<bean class="org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter"/>

<!--  This is responsible for forwarding web service request to the correct adapters.
This is exactly similar to Spring MVC's DispatcherServlet -->
<bean id="messageDispatcher" class="org.springframework.ws.server.MessageDispatcher">
        <property name="endpointAdapters">
            <list>
                <ref bean="defaultMethodEndpointAdapter"/>
            </list> 
        </property>
 </bean>

 <!--  See reference at the beginning of this document -->
 <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <value>
            /ws=messageDispatcher
            /ws/service.wsdl=service
        </value>
    </property> 
</bean>

<!--  See reference at the beginning of this document -->

弹簧ws.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:p="http://www.springframework.org/schema/p" 
            xmlns:sws="http://www.springframework.org/schema/web-services"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:oxm="http://www.springframework.org/schema/oxm"
            xsi:schemaLocation=
                "http://www.springframework.org/schema/beans 
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
                http://www.springframework.org/schema/web-services 
                http://www.springframework.org/schema/web-services/web-services-2.0.xsd 
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context-3.1.xsd 
                http://www.springframework.org/schema/oxm 
                http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd ">

<!-- Uses the latest feature from 2.0.0 RC2. 
    Enables @Endpoint and related Spring-WS annotations. See Spring WS Reference 5.4-->
 <sws:annotation-driven />

 <!-- Uses the latest feature from 2.0.0 RC2. 
    Enables interceptor endpoints. See Spring WS Reference 5.5.2
    Here we have an interceptor that validates XML request and a logger
    -->
 <sws:interceptors>
        <bean id="validatingInterceptor"  class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"
                    p:schema="/WEB-INF/service.xsd"
                    p:validateRequest="true"
                    p:validateResponse="true"/>

        <bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>

        <bean class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
            <property name="validationActions" value="UsernameToken"/>
            <property name="securementActions" value="UsernameToken"/>
            <property name="securementUsername" value="name"/>
            <property name="securementPassword" value="password"/>
            <property name="validationCallbackHandler" ref="callbackHandler" />
        </bean>
 </sws:interceptors>

<!-- a simple callback handler to configure users and passwords with an in-memory Properties object. -->
<bean id="callbackHandler" class="org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler">
    <property name="users">
        <props>
            <prop key="admin">admin</prop>
            <prop key="manager">manager</prop>
        </props>
    </property>
</bean>

<!-- Uses the latest feature from 2.0.0 RC2. 
    Enables publishing of wsdl. See Spring WS Reference 3.7
    For dynamic location transformation to work, a special parameter must be added to the web.xml.
    The locationUri here has no use when integrated with Spring MVC because 
    it has been overriden by the SimpleUrlHandlerMapping -->
<sws:dynamic-wsdl id="service"                                                           
    portTypeName="ServicePort"                                                         
    locationUri="/ws"                                                       
    targetNamespace="http://Controller.webservice.java.com">                               
  <sws:xsd location="/WEB-INF/service.xsd"/>                                                  
</sws:dynamic-wsdl>

<!--  Our mashaller. You can use any marshaller you want.
 For info on how to use Castor, see http://www.castor.org/xml-mapping.html#2.1-Marshalling-Behavior -->
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"
    p:mappingLocation="/WEB-INF/castor-mapping.xml" />

<!-- Normally we use the GenericMarshallingMethodEndpointAdapter however if you read the Spring WS 2.0 API for this adapter:
 "Deprecated. as of Spring Web Services 2.0, in favor of DefaultMethodEndpointAdapter and MarshallingPayloadMethodProcessor."
 See http://static.springsource.org/spring-ws/sites/2.0/apidocs/org/springframework/ws/server/endpoint/adapter/GenericMarshallingMethodEndpointAdapter.html

 So we have to implement using the recommended implementation. The advantage of these two classes is that
 we have a pluggable adapter. For more info, check the Spring WS 2.0 API and its source code.
 -->
<bean id="marshallingPayloadMethodProcessor" class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
    <constructor-arg ref="castorMarshaller"/>
    <constructor-arg ref="castorMarshaller"/>
</bean>

<bean id="defaultMethodEndpointAdapter" class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
    <property name="methodArgumentResolvers">
        <list>
            <ref bean="marshallingPayloadMethodProcessor"/>
        </list> 
    </property>
    <property name="methodReturnValueHandlers">
        <list>
            <ref bean="marshallingPayloadMethodProcessor"/>
        </list>
    </property>
</bean>

1 个答案:

答案 0 :(得分:0)

尝试升级wss4j 1.6:https://jira.spring.io/browse/SWS-711。或者我认为存在api兼容性问题,你必须使用正确的WSS4J 1.6.x和spring framework