我想以編程方式將DataSource對象綁定到(eclipse)jetty的JNDI上下文。我需要測試目的。下面是一段代碼,我現在有:Jetty綁定JNDI上下文中的數據源
server = new Server(SERVER_PORT);
webAppContext = new WebAppContext();
webAppContext.setResourceBase(".");
webAppContext.setContextPath("/" + SERVER_CONTEXT);
webAppContext.addEventListener(prepareServletContextListener());
webAppContext.addFilter(GuiceFilter.class, "/*", null);
webAppContext.addServlet(DefaultServlet.class, "/");
Resource r = new Resource(webAppContext,"jdbc/testDS",createDataSource());
server.setHandler(webAppContext);
server.start();
當然與資源行不working.I不知道如何以編程方式綁定它來獲取某物類似於:
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/DSTest</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/databasename</Set>
<Set name="User">user</Set>
<Set name="Password">pass</Set>
</New>
</Arg>
</New>
任何幫助將不勝感激。
請解釋資源如何連接到服務器! –