无法创建JAXBContext java Web服务

时间:2014-05-21 14:14:49

标签: java oracle web-services

我开始学习Web服务,我想创建一个连接到数据库的简单自定义:

import java.sql.*;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class DatabaseService{
Connection conn;
@WebMethod
public Connection getDBConnection(){
  try{
   Class.forName("oracle.jdbc.driver.Oracledriver");
   String url = "jdbc:oracle:thin:@localhost:1521:mysid";
   conn = driverManager.getConnection(url, "myusername", "mypassword");
   }catch(Exception asd){
    System.out.println(asd.getMessage());
  }
     return conn;
  }
 }

我有一个主要方法来调用它:

import javax.xml.ws.Endpoint;
public class CallService{
  public static void main(String[] args){
   Endpoint.publish("http://localhost:8080/kollega_services", new DatabaseService());
   System.out.println("service Started");
  }
}

当我执行时,我收到此错误:

 Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext
        at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:153)
        at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:83)
        at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:244)
        at com.sun.tools.internal.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:229)
        at com.sun.tools.internal.ws.wscompile.WsgenTool.run(WsgenTool.java:112)
        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.tools.internal.ws.Invoker.invoke(Invoker.java:105)
        at com.sun.tools.internal.ws.WsGen.main(WsGen.java:41)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
        this problem is related to the following location:
        at java.sql.Connection
        at public java.sql.Connection.webservice.jaxws.GetDBConnectionResponse._return
        at webservice.jaxws.GetDBConnectionResponse
 at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:140)
        ... 10 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
        this problem is related to the following location:
                at java.sql.Connection
        at public java.sql.Connection.webservice.jaxws.GetDBConnectionResponse._return
        at webservice.jaxws.GetDBConnectionResponse

        at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:277)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
        at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
        at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:95)
        at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:97)
        at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:148)
        at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:140)
        ... 12 more

我还需要添加什么来使其成功?

0 个答案:

没有答案