對不起,如果這個問題似乎是重複的,但我無法從現有帖子的搜索結果中閃現出可行的解決方案。如何在Eclipse中設置GWT/Jetty連接池?
我有一個使用JDBC連接池的Web應用程序。連接池資源在war文件的meta-inf/context.xml中定義。當我將war文件部署到tomcat時,該文件被複制(並重命名爲匹配我的war文件名)到tomcat的conf/catalina/localhost文件夾中。我的代碼獲取連接的數據源對象是這樣的:
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
datasource = (DataSource) envCtx.lookup("jdbc/MYDB");
和我的context.xml中定義了以下資源:
<Resource name="jdbc/MYDB"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
username="username"
password="password"
url="jdbc:sqlserver://myremote.database.server:1433;databaseName=testdb"
/>
所有這一切都工作得很好,當戰爭文件部署到Tomcat。然而,在eclipse開發過程中,由於GWT依賴關係,我經常需要使用GWT內置的jetty容器進行調試。
當我這樣做時,InitialContext的()調用失敗,出現以下消息:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
我試圖用碼頭-env.xml在戰爭中的WEB-INF,但沒有工作,要麼(同錯誤),可能是jetty-env.xml或其他語法中的語法錯誤。
這裏是我的碼頭-ENV:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="OTMFTDB" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/MYDB</Arg>
<Arg>
<New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<Set name="User">username</Set>
<Set name="Password">password</Set>
<Set name="DatabaseName">testdb</Set>
<Set name="ServerName">myremote.database.server</Set>
<Set name="PortNumber">1433</Set>
</New>
</Arg>
</New>
</Configure>
最後一兩件事,如果我改變了碼頭-env.xml到碼頭-web.xml中的名稱,然後在我得到一個503 HTML錯誤時我嘗試連接瀏覽器。 (eclipse顯示以下錯誤: [WARN]上下文啓動失敗com.g[email protected]111a20c {/,E:\ dev \ src \ servers \ webservice \ war} java .lang.ClassNotFoundException:org.eclipse.jetty.server.Server)
所以我認爲jetty-env沒有加載並且jetty-web是,但是我的jetty-web顯然干擾了GWT的jetty設置。
感謝您的詳細解答!我嘗試了它,它不適合我。我相信那是因爲我使用了一個更新的GWT(2.6.0),我相信這是使用Jetty 8.1.12,基於這個SO回答(https://stackoverflow.com/a/17592318)。我相信配置文件和類名稱會有所不同,但我無法在線查找Jetty 8文檔(只有Jetty 9.3.x可用)。無論如何,我將嘗試遵循Jetty 9的指令(這裏:https://www.eclipse.org/jetty/documentation/9.3.x/using-jetty-jndi.html)。如果您有任何見解,請與我分享。 – leeyuiwah 2017-11-12 23:20:50