2016-07-26 13 views
0

我正在爲Tomcat 8部署一個簡單的Java 7(我使用Maven進行項目設置,依賴關係等)web應用程序,我有一個META-INF /context.xml我需要指定數據庫資源:META-INF/context.xml在我的Java Web應用程序中導致問題

項目/ src目錄/主/資源/ META-INF/context.xml的

<xml version="1.0" encoding="UTF-8"?> 
<Context> 
    <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" 
      maxTotal="100" maxIdle="30" maxWaitMillis="10000" 
      username="root" password="root" driverClassName="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://127.0.0.1:3306/javatest"/> 
</Context> 

當我刪除此META-INF /上下文.xml文件,我能夠訪問我的jsps,但是,當然,由於我的數據源丟失,它們會返回錯誤。但是,當我將META-INF/context.xml包含回該項目時,我試圖訪問的所有資源都給了我一個404。爲什麼它的行爲如此?

For reference, I am trying how to use a JNDI data source by following this guide.我沒有一切必要在該項目

回答

0

步驟是否有任何異常,當服務器開始?

如果jdbc驅動程序沒有捆綁在WEB-INF/lib中而不在CATALINA_BASE/lib中,那麼它找不到該類。這很可能會導致啓動失敗。

檢查catalina.out的(如果你是在UNIX上)或CATALINA_BASE /日誌/本地主機/ catalina.date.log

編輯

只注意到你的src /主/資源/ META- INF

嘗試的src/main/的webapp/META-INF /context.xml ...

+0

不,根本沒有例外。我認爲我的應用程序中的context.xml文件與它的路徑混淆。我還確保用於Java的Connector/J 3.0.11-stable在$ CATALINA_BASE/lib中。 – mpmp

+0

這似乎很奇怪。我始終沒有問題地使用app.war/META-INF/context.xml文件。你是否僅僅使用本地爆炸式應用程序來做這件事? –

+0

我基本上做了一個「mvn clean install」來生成我的war文件。我從目標目錄抓取它並直接安裝到$ CATALINA_BASE/webapps。 – mpmp

0

不要取下META-INF/context.xml,因爲它是默認的配置爲項目而努力!也不要輸入生產密碼到默認的META-INF/context.xml

改爲使用copyXML="true"!首次部署到tomcat時,META-INF/context.xml被永久複製到tomcat/conf/Catalina

Set to true if you want a context XML descriptor embedded inside the application 
(located at /META-INF/context.xml) to be copied to xmlBase when the application is 
deployed. On subsequent starts, the copied context XML descriptor will be used in 
preference to any context XML descriptor embedded inside the application even if the 
descriptor embedded inside the application is more recent. The flag's value defaults to 
false. Note if deployXML is false, this attribute will have no effect. 

第一次部署後更新tomcat/conf/Catalina/webappname.xml生產性的數據庫信息。

任何重新部署將繼續使用tomcat/conf/Catalina/webappname.xml

相關問題