2

sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
  <endpoint implementation="ways.org.commerce.inventory.service.InventoryServiceImpl" name="InventoryServiceImpl" url-pattern="/services/InventoryServiceImpl"/>
</endpoints>

web.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">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext-Main.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>InventoryServiceImpl</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>InventoryServiceImpl</servlet-name>
        <url-pattern>/services/InventoryServiceImpl</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

InventoryServiceImpl.java

@WebService(serviceName = "InventoryServiceImpl")
public class InventoryServiceImpl implements IFInventoryService {

    private IFInventoryDAO inventoryDAO;

    @WebMethod(exclude = true)
    public IFInventoryDAO getInventoryDAO() {
        return inventoryDAO;
    }

    @WebMethod(exclude = true)
    public void setInventoryDAO(IFInventoryDAO inventoryDAO) {
        this.inventoryDAO = inventoryDAO;
    }

    @WebMethod(operationName = "addProduct")
    public void addProduct(
            @WebParam(name = "product") ProductBean product) throws CommerceBaseException {
        if (inventoryDAO.productExists(product.getProductUniqueCode())) {
            throw new CommerceBaseException("Product Not Found", InventoryErrorCode.PRODUCT_NOT_FOUND_ERROR);
        }
        inventoryDAO.addProduct(product);
    }

    @WebMethod(operationName = "getProduct")
    public ProductBean getProduct(
            @WebParam(name = "productUniqueCode") String productUniqueCode) throws CommerceBaseException {
        if (inventoryDAO.productExists(productUniqueCode)) {
            throw new CommerceBaseException("Product Not Found", InventoryErrorCode.PRODUCT_NOT_FOUND_ERROR);
        }
        return inventoryDAO.getProduct(productUniqueCode);
    }

    @WebMethod(operationName = "productExists")
    public boolean productExists(
            @WebParam(name = "productUniqueCode") String productUniqueCode) {
        return inventoryDAO.productExists(productUniqueCode);
    }
}

I am getting following exception

SEVERE: Exception sending context initialized event to listener instance of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to parse runtime descriptor: java.lang.IllegalArgumentException: Prefix '' is already bound to ''
    at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:139)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Prefix '' is already bound to ''
    at com.sun.xml.txw2.StartTag.addNamespaceDecl(StartTag.java:171)
    at com.sun.xml.txw2.ContainerElement._namespace(ContainerElement.java:313)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.xml.txw2.ContainerElement.invoke(ContainerElement.java:114)
    at $Proxy179._namespace(Unknown Source)
    at com.sun.xml.ws.wsdl.writer.WSDLGenerator.generateDocument(WSDLGenerator.java:339)
    at com.sun.xml.ws.wsdl.writer.WSDLGenerator.doGeneration(WSDLGenerator.java:272)
    at com.sun.xml.ws.server.EndpointFactory.generateWSDL(EndpointFactory.java:443)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:209)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:505)
    at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:253)
    at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147)
    at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:124)
    ... 8 more
20 Oct, 2012 11:17:18 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext

Please help me to figure out where i am doing mistake...

4

3 回答 3

3

您的 Web 服务库和 tomcat 的库之间存在冲突。

使用以下依赖:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.2.8</version>
    <scope>provided</scope>
</dependency>
于 2013-12-24T12:49:47.050 回答
0

我有同样的问题。

我正在使用webservice-rt-1.4Maven's dependency修复了webservice-api罐子也与COMPILE范围一起出现的人。然后在maven里改成PROVIDEscope,把webservice-rt-1.4放到tomcat里面。还要检查 XML 的应用程序库与 tomcat 之间的冲突。希望情况也是如此。拥抱!

于 2013-06-13T20:11:46.853 回答
0

就我而言,是为 Web 服务生成的 war 文件中包含的 jaxws-rt.jar 导致了问题,但是一旦我清理并再次构建 war 并保持提供的依赖关系,它就可以正常工作

于 2015-06-01T10:02:59.493 回答