java.lang.IllegalArgumentException:前缀''已绑定到''

时间:2012-10-20 17:50:47

标签: spring xml-namespaces illegalargumentexception

太阳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);
    }
}

我遇到了异常

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

请帮我弄明白我在哪里做错了......

3 个答案:

答案 0 :(得分:3)

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

使用以下依赖性:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.2.8</version>
    <scope>provided</scope>
</dependency>

答案 1 :(得分:0)

我遇到了同样的问题。

我正在webservice-rt-1.4使用Maven's dependency并修复webservice-api jar也随COMPILE范围而来的人。然后在Maven中更改为PROVIDE范围,并将webservice-rt-1.4放入tomcat中。 另外检查应用程序的XML的lib与tomcat之间的冲突。 希望情况也是如此。 拥抱!

答案 2 :(得分:0)

在我的情况下,为web服务生成的war文件中包含的jaxws-rt.jar导致了问题但是一旦我清理并再次构建了战争,保持依赖性,它工作正常