java - tomcat 上的 JAX-WS webservice - 无法实例化

标签 java web-services tomcat

我想知道如何处理这种情况。 我所做的是遵循教程 http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat-ssl-connection/ 要创建类似的安全 Web 服务,我能够实现它,但我有一个错误,

ml.ws.api.server.InstanceResolver.createNewInstance(InstanceResolver.java:222) 在 com.sun.xml.ws.api.server.InstanceResolver.createDefault(InstanceResolver.java:184) 在 com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:209)

错误是因为我正在实例化 web 服务,例如从这个例子中,HelloWorldImpl 类有一个带有参数的构造函数来设置类的参数。 我明白,在 Jax-ws 网络服务中只有默认构造函数是可能的,但在那种情况下我想知道如何处理这个?

说喜欢

package com.mkyong.ws;

import javax.jws.WebService;

//Service Implementation Bean

@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
private ABC abc;
 public HelloWorldImpl (ABC abc)
{
    this.abc = abc;
}
    @Override
    public String getHelloWorldAsString() {
        return "Hello World JAX-WS";
    }

// and i use this abc in one of the methods 
}

最佳答案

这不是构造函数的正确表示法:

public void HelloWorldImpl (ABC abc) {
    this.abc = abc;
}

应该是:

public HelloWorldImpl (ABC abc) {
    this.abc = abc;
}

更新:那么为什么不添加默认构造函数呢?

package com.mkyong.ws;

import javax.jws.WebService;

//Service Implementation Bean

@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
private ABC abc;

public HelloWorldImpl() { 
    this("Hello World JAX-WS");
}

 public HelloWorldImpl (ABC abc)
{
    this.abc = abc;
}
    @Override
    public String getHelloWorldAsString() {
        return this.getAbc();
    }

// and i use this abc in one of the methods 
}

关于java - tomcat 上的 JAX-WS webservice - 无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30217830/

相关文章:

java - 将 CXF SOAP Web 服务部署到 Apache Tomcat

java - Spring 3 MVC - 在生产中找不到 Url 映射 (404)

java - 多种布局显示及切换的UI设计建议

java - 如何从org.jdom.Document中的xml对象获取数据?

java - 在服务器上以编程方式添加拦截器

java - Jersey 1.91.x 404 错误

maven - 如何从 Liferay 7 取消部署 portlet?

java - Dynamic Appcompat Theme 导致 Activity 背景失败

c# - 使用 IP :PORT/PATH 的 TCPClient()

java - 如何从 Java 类调用 SOAP Web 服务?