gpt4 book ai didi

java - 生成 WebService 工件时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:51 24 4
gpt4 key购买 nike

我在为 Web 服务生成消息和响应工件时遇到一些问题。当我尝试时,我在 cmd 中遇到此错误:

C:\Users\KingMarkMcC\workspace\WebServiceJX>wsgen -cp -keep . WebServiceImp option "-classpath" requires an argument

这是我的WebServiceInterface:

package CacheServer;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style= Style.DOCUMENT)
public interface WebServiceInterface {

@WebMethod Object get(Object k);
@WebMethod void put(Object k, Object v);
@WebMethod void remove(Object k);
@WebMethod void flush();
@WebMethod int size();
}

下面是我的 WebService 实现 封装CacheServer;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.jws.WebService;


@WebService(endpointInterface = "CacheServer.WebServiceInterface")

public class WebServiceImp implements WebServiceInterface{

CacheDataStruct cache;

WebServiceImp(int i){
cache = new CacheDataStruct(i);
}

//Getting from Cache
@Override
public Object get(Object k){
System.out.println("GET REQUESTED");
return getter(k);
}
private Object getter(Object k){
return cache.get(k);
}

//Putting into Cache
@Override
public void put(Object k, Object v){
System.out.println("PUT REQUESTED");
putter(k,v);
}
private void putter(Object k, Object v){
cache.put(k, v);
}

//Removing from Cache
@Override
public void remove(Object k){
System.out.println("REMOVE REQUESTED");
remover(k);
}
private void remover(Object k){
cache.remove(k);
}

//Getting size of Cache
@Override
public int size(){
System.out.println("SIZE REQUESTED");
return sizer();
}
private int sizer(){
return cache.size();
}

//Flushing Cache
@Override
public void flush(){
System.out.println("FLUSH REQUESTED");
flusher();
}
private void flusher(){
cache.flush();
}

class CacheDataStruct extends LinkedHashMap<Object,Object>{
private static final long serialVersionUID = -8892618408950826874L;
public final int CACHESIZE;
private final static float loadFactor =0.75f;

protected boolean removeEldestEntry(Map.Entry<Object, Object> eldest) {
return size() > CACHESIZE;
}

public CacheDataStruct(int cacheSize){
super(cacheSize,loadFactor,true);
this.CACHESIZE=cacheSize;
}

void flush(){
clear();
System.out.println("Cache has been cleared.");
}
}
}

任何有关生成工件的帮助将不胜感激!

最佳答案

经过分析,我发现这里的第一个挑战在于您的服务实现 Bean (SIB) WebServiceImp。您的 SIB 使用了无效的构造函数:包访问构造函数,因此为了公开您的服务,您需要添加一个公共(public)无参数构造函数

As defined by JSR 181, a class annotated with javax.jws.WebService must have a default public constructor. A SIB class must be a top level class or a static inner class.

SIB 构造函数示例:

    public WebServiceImp() {}
public WebServiceImp(int i) {
cache = new CacheDataStruct(i);
}

完成上述更改后,可能在编译后(javac CacheServer/*.java),您可以运行 wsgen 命令或简单地运行以下命令(在 src 文件夹中):

     wsgen -cp "." -wsdl CacheServer.WebServiceImp

还可以找到另一种传递参数的方法,而不是使用 SIB 中的构造函数,也许将需要 arg 构造函数的对象的实例化委托(delegate)给另一个 POJO。

关于java - 生成 WebService 工件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40487074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com