【发布时间】:2016-03-26 07:44:59
【问题描述】:
我知道这看起来像是一个重复的问题,但我尝试了 stackoverflow 和其他论坛中的所有帖子,但无济于事。
Apache Tomcat 8.0.32 运行 MySQL 5.6 的 Amazon RDS 在 EC2 windows 服务器上运行 tomcat
我的 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
...
<resource-ref>
<description>datasource</description>
<res-ref-name>jdbc/bbDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
...
</web-app>
Context.xml 位于我的应用程序的 META-INF 文件夹中:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ch">
<Resource name="jdbc/bbDataSource"
auth="Container"
type="javax.sql.DataSource"
username="********"
password="********"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://*url*:3306/x?zeroDateTimeBehavior=convertToNull"/>
</Context>
在 ServletContextListener 中创建数据源
try {
dataSource = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/bbDataSource");
mLogger.log(Level.CONFIG, "Startup - AppContextServletListener - contextInitialized - Created dataSource object: {0}", dataSource);
sce.getServletContext().setAttribute("dataSource", dataSource);
}
启动过程中没有问题。 访问 dataSource tomcat 时会引发上述错误。 jar 文件位于 tomcat 的 lib 文件夹中(我怀疑这是问题所在,因为我也在同一个应用程序中使用 hibernate,它能够毫无问题地访问数据库)。
我还注意到以下几点:$CATALINA_HOME/conf/Catalina/localhost 没有 'ch.xml' -> 尝试复制 context.xml 并在那里重命名为 'ch.xml' 但无济于事。
server.xml -> 宿主节点下
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/ch" docBase="ch"></Context>
<Context path="/ch/asdasd" docBase="C:\\xasdasd\\asdasd"> </Context>
【问题讨论】:
-
不是真的-> 'server.xml' 的问题有资源声明/定义。在这种情况下,'context.xml' 有它。
-
我不确定,我在“相关”下看到很多类似的问题,这些问题都归结为错误的名称或错误的配置位置;你可能也想看看这些。
标签: mysql tomcat jdbc driver tomcat8