META-INF/context.xml 导致我的 Java Webapp 出现问题
META-INF/context.xml causing problems in my Java Webapp
我正在部署一个简单的 Java 7(我使用 Maven 进行项目设置、依赖关系等)网络应用程序到 Tomcat 8,我有一个 META-INF/context。 xml 我需要指定我的数据库资源:
project/src/main/resources/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/context.xml 文件时,我可以访问我的 jsps,但是,当然,它们会出现 return 错误,因为我的数据源丢失了。但是,当我将 META-INF/context.xml 包含回项目时,我尝试访问的所有资源都会给我一个 404。为什么会这样?
For reference, I am trying how to use a JNDI data source by following this guide. 我完成了该项目中所有必要的步骤
服务器启动时有没有异常?
如果 jdbc 驱动程序未捆绑在 WEB-INF/lib 中且未捆绑在 CATALINA_BASE/lib 中,则它无法找到 class。这很可能会导致启动失败。
检查catalina.out(如果你在unix上)或CATALINA_BASE/logs/localhost/catalina。date.log
编辑
刚注意到你有 src/main/resources/META-INF
尝试src/main/webapp/META-INF/context.xml ...
不要删除 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
。
我正在部署一个简单的 Java 7(我使用 Maven 进行项目设置、依赖关系等)网络应用程序到 Tomcat 8,我有一个 META-INF/context。 xml 我需要指定我的数据库资源:
project/src/main/resources/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/context.xml 文件时,我可以访问我的 jsps,但是,当然,它们会出现 return 错误,因为我的数据源丢失了。但是,当我将 META-INF/context.xml 包含回项目时,我尝试访问的所有资源都会给我一个 404。为什么会这样?
For reference, I am trying how to use a JNDI data source by following this guide. 我完成了该项目中所有必要的步骤
服务器启动时有没有异常?
如果 jdbc 驱动程序未捆绑在 WEB-INF/lib 中且未捆绑在 CATALINA_BASE/lib 中,则它无法找到 class。这很可能会导致启动失败。
检查catalina.out(如果你在unix上)或CATALINA_BASE/logs/localhost/catalina。date.log
编辑
刚注意到你有 src/main/resources/META-INF
尝试src/main/webapp/META-INF/context.xml ...
不要删除 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
。