我想知道如何处理这种情况。 我所做的是遵循教程 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/