简体   繁体   English

Tomcat上的JAX-WS Web服务-无法实例化

[英]JAX-WS webservice on tomcat - cannot be instantiated

I would like to know how to handle this situation. 我想知道如何处理这种情况。 what i have done is i have followed the tutorial http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat-ssl-connection/ to create a similar secured web service, i am able to achieve it, but i have a error , 我所做的是我已经按照教程http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat-ssl-connection/创建了类似的安全网络服务,我能够实现,但是有一个错误,

ml.ws.api.server.InstanceResolver.createNewInstance(InstanceResolver.java:222) at com.sun.xml.ws.api.server.InstanceResolver.createDefault(InstanceResolver.java:184) at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:209) 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)

the error is because i am instantiating the webservice for example from this example the HelloWorldImpl class has a constructor with arguments to set a parameter from a class. 该错误是因为我正在从该示例实例化Web服务,例如,HelloWorldImpl类具有一个构造函数,该构造函数具有用于从类中设置参数的参数。 I understand , only default constructor is possible in Jax-ws web service, but in that case i want to know how to handle this? 我了解,Jax-ws Web服务中只能使用默认构造函数,但是在那种情况下,我想知道如何处理?

say like 说像

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 
}

This is not the correct notation for a constructor: 这不是构造函数的正确表示法:

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

Should be: 应该:

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

Update: So why not add a default constructor? 更新:那么为什么不添加默认构造函数呢?

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 
}

I think you can control how the HelloWorldImpl gets created by using: @InstanceResolverAnnotation 我认为您可以使用以下方法控制如何创建HelloWorldImpl: @InstanceResolverAnnotation

I wasn't able to find any good example, but here is one link that uses this annotation: http://blog.vinodsingh.com/2008/12/let-spring-load-service-class-for-jax.html 我找不到任何好的示例,但是这里有一个使用此注释的链接: http : //blog.vinodsingh.com/2008/12/let-spring-load-service-class-for-jax.html

The idea is that the class specified as the Value for this Annotation, will be used to create the Instance of HelloWorld WebService. 这个想法是,指定为此Annotation的Value的类将用于创建HelloWorld WebService的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM