Модуль не был развернут - PullRequest
0 голосов
/ 26 июня 2018

Я пытаюсь создать веб-сервис в веб-приложении на NetBeans 8.2 (server-tomcat 8.0.27.0), который может подключаться к базе данных на Postgres и читать таблицу с именем «test». у меня есть этот код в download.java (веб-сервис в пакете под названием serve)

Download.java

@WebService(serviceName = "download")
public class Download {

    Connection con=null;    

    private DataSource getJdbcPostgres() throws NamingException, SQLException {
        Context c = new InitialContext();
        DataSource ds=(DataSource) c.lookup("java:comp/env/jdbc/postgres");
        con=ds.getConnection();
        return ds;
   }

   @WebMethod(operationName = "download")
   public String download(@WebParam(name = "username")String username, @WebParam(name = "id")String id) throws ClassNotFoundException, SQLException {

       String sql = "select * from test where id="+id;
       Class.forName("org.postgresql.Driver");
       PreparedStatement pst=con.prepareStatement(sql);
       ResultSet rs=pst.executeQuery();
       ResultSetMetaData rsmd=rs.getMetaData();
       rs.next();
       return "";
   } 

}

вот мой файл context.xml (в META-INF)

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/service2">
 <Resource name="jdbc/postgres" auth="Container"
      type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
      url="jdbc:postgresql://localhost:5432/postgres"
      username="someusername" password="somepassword" maxTotal="20" maxIdle="10"
      maxWaitMillis="-1"/>
 </Context>

и вот web.xml (в WEB-INF):

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
   <listener>
       <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
   </listener>
   <servlet>
       <servlet-name>download</servlet-name>
       <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
       <servlet-name>download</servlet-name>
       <url-pattern>/download</url-pattern>
   </servlet-mapping>
   <session-config>
       <session-timeout>
           30
       </session-timeout>
   </session-config>
   <resource-ref>
       <description>postgreSQL Datasource example</description>
       <res-ref-name>jdbc/postgres</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>
</web-app>

команда clean and build выполнена успешно, но не развертывается на сервере Apache Tomcat сообщение об ошибке (выводится при попытке развернуть его):

Checking data source definitions for missing JDBC drivers...
Undeploying ...
undeploy?path=/service2
OK - Undeployed application at context path /service2
In-place deployment at D:\NetBeansProjects\service2\build\web
Deployment is in progress...
deploy?config=file%3A%2FC%3A%2FUsers%2FTRAINE%7E3%2FAppData%2FLocal%2FTemp%2Fcontext1366288511044657094.xml&path=/service2
FAIL - Deployed application at context path /service2 but context failed to start
D:\NetBeansProjects\service2\nbproject\build-impl.xml:1094: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 2 seconds)

когда я пытался изменить сервер на GlassFish 4.1.1, он говорит:

Severe:   WSSERVLET11: failed to parse runtime descriptor: 
com.sun.xml.ws.spi.db.DatabindingException: 
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of 
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle 
interfaces.
    this problem is related to the following location:
        at javax.xml.transform.SourceLocator
        at public javax.xml.transform.SourceLocator 
     serve.jaxws.TransformerConfigurationExceptionBean.locator
        at serve.jaxws.TransformerConfigurationExceptionBean
Caused by: com.sun.xml.ws.spi.db.DatabindingException: 
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of 
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle 
interfaces.
    this problem is related to the following location:
        at javax.xml.transform.SourceLocator
        at public javax.xml.transform.SourceLocator 
serve.jaxws.TransformerConfigurationExceptionBean.locator
        at serve.jaxws.TransformerConfigurationExceptionBean
Severe:   Exception while loading the app
Severe:   Undeployment failed for context /service2
Severe:   Exception while loading the app : java.lang.IllegalStateException: 
ContainerBase.addChild: start: org.apache.catalina.LifecycleException: 
org.apache.catalina.LifecycleException: javax.servlet.ServletException: 
com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to 
parse runtime descriptor: com.sun.xml.ws.spi.db.DatabindingException: 
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of 
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle 
interfaces.
    this problem is related to the following location:
        at javax.xml.transform.SourceLocator
        at public javax.xml.transform.SourceLocator serve.jaxws.TransformerConfigurationExceptionBean.locator
        at serve.jaxws.TransformerConfigurationExceptionBean

Я новичок в этой области, поэтому, пожалуйста, помогите мне, если я где-то не прав или что-то упустил!

1 Ответ

0 голосов
/ 29 июня 2018

Я не знаю, почему это произошло, но я просто поставил try-catch вместо бросков, и он будет развернут!

@WebMethod(operationName = "download")
public String download(@WebParam(name = "username")String username, @WebParam(name = "id")String id) {
try {
        String sql="select * from test";
        Connection conn=myDatasource.getConnection();
        PreparedStatement pst=conn.prepareStatement(sql);
        rs=pst.executeQuery();
        }
    catch (SQLException ex) {
        Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
    }
return "someString";
}

Кто-нибудь может подсказать, почему это не сработало раньше? Хотя моя проблема все же решена, мне любопытно узнать, что не так с «исключениями бросков»! Постскриптум Я запускаю его на GlassFish 4.1.1 на этот раз

...