如何获得与jboss的数据源连接为7 resteasy

问题描述

通常,在使用Servlet时,我通常在servletcontextlistener中初始化数据源,如下所示:

public class DBConnectionListener implements servletcontextlistener {

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        // Todo Auto-generated method stub
    }

    @Override
    public void contextinitialized(ServletContextEvent sce) {
        try {     
            // Obtain our environment naming context
            Context ctx = new InitialContext();

            // Look up data source web service in order to determine whether ws is up or not
            DataSource dsWs = (DataSource) ctx.lookup("java:jboss/datasources/wsmanager");
            DataSource dsnew = (DataSource) ctx.lookup("java:jboss/datasources/mradbnew");
            sce.getServletContext().setAttribute("DBCPool",dsnew);
            sce.getServletContext().setAttribute("wsmngr",dsWs);

        } catch (NamingException e) {
          e.printstacktrace();
            Utility.LogError(e);
        }
    }

}

然后在每个servlet中,我在初始化生命周期中获得连接,如下所示:

     public void init(ServletConfig config) throws servletexception {
        super.init(config);
        
        dataSourceDBC = (DataSource) getServletContext().getAttribute("DBCPool");
        dataSourceWSMNGR = (DataSource) getServletContext().getAttribute("wsmngr");
      }

  public static synchronized Connection getProfileConnection() throws sqlException {
    return dataSourceDBC.getConnection();
  }

我只需要一些帮助,以按照下面定义的端点在jboss中使用Resteasy实现相同的目的

@Path("/session")
public class ReservationSessionEndpoint {
    /**
     * Method that will return the newly created session
     * 
     * @param reservationTicketId
     * @return
     */
    @POST
    @Path("/")
    @Produces(MediaType.APPLICATION_JSON)
    public Response createSession(@HeaderParam("reservationTicketId") String reservationTicketId) {
        return Response.status(200).build();
    }
}

感谢您的帮助, 阿什利

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)