开发者社区> 问答> 正文

tomcat 7 在项目的/META-INF/context.xml配置数据源不起作用 配置报错 

我使用tomcat7来开发项目,看了下官方文档,推荐在项目的/META-INF/context.xml中配置数据源,但是我配了之后,根本就不起作用。web.xml里面也加了数据源的引用的。在server.xml里面配数据源是起作用的。麻烦大家帮忙解决下。感激不尽。 /META-INF/context.xml的配置如下:

<?xml version="1.0" encoding="UTF-8"?>

<Context path="" docBase="webcontext" reloadable="true" 
         workDir="D:\eclipsespace\db\webcontext\WEB-INF\work"
	 sessionCookieName="DB_SESSION" sessionCookiePath="/">
			
    <Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"
	      maxActive="10" maxIdle="5" maxWait="10000"
	      username="root" password="123456" 
              driverClassName="com.mysql.jdbc.Driver"
	      url="jdbc:mysql://localhost:3306/abc?useUnicode=true&characterEncoding=UTF-8"/>
</Context>

展开
收起
kun坤 2020-05-30 23:27:12 714 0
1 条回答
写回答
取消 提交回答
  • 我的Tomcat7是这么配的,使用没问题。 先在/META-INF/context.xml中配置:

    <Context> <!-- MySQL DBCP --> <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/msys" username="root" password="123456" maxActive="100" maxIdle="30" maxWait="10000" /> </Context>

    再在web.xml里配置一下 resource-ref

    <resource-ref>
    	<description>MySQL DBCP</description>
    	<res-ref-name>jdbc/mysql</res-ref-name>
    	<res-type>javax.sql.DataSource</res-type>
    	<res-auth>Container</res-auth>
    </resource-ref>

    ######参考我的以前写文章,应该可以: http://www.blogjava.net/ytl-zlq/archive/2009/04/14/265564.html######

    引用来自“tsl0922”的答案

    我的Tomcat7是这么配的,使用没问题。 先在 /META-INF/context.xml中配置:
    <Context>
    	<!-- MySQL DBCP -->
    	<Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource"
    		driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/msys"
    		username="root" password="123456" maxActive="100" maxIdle="30"
    		maxWait="10000" />
    </Context>
    再在web.xml里配置一下 resource-ref
    <resource-ref>
    	<description>MySQL DBCP</description>
    	<res-ref-name>jdbc/mysql</res-ref-name>
    	<res-type>javax.sql.DataSource</res-type>
    	<res-auth>Container</res-auth>
    </resource-ref>
    这个应该是工作的,文档上有例子 ###### 我遇到和你同样的问题:应该适合你 http://my.oschina.net/artshell/blog/199669
    2020-05-30 23:27:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Apache Tomcat 的云原生演进 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多