春季在Tomcat中使用JNDI ...为什么我的项目中需要META-INF/context.xml [英] Spring using JNDI with Tomcat... why do I need a META-INF/context.xml in my project

查看:89
本文介绍了春季在Tomcat中使用JNDI ...为什么我的项目中需要META-INF/context.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Spring使用tomcat JNDI资源来访问我的数据库.如果我的项目中包含资源信息的META-INF/context.xml,我的项目就可以工作,但是一旦删除它,它就会停止..为什么.

I am trying to get Spring working with tomcat JNDI resource to access my database. My project works if a META-INF/context.xml in my project with the resource information but once I remove it it stops.. why.

推荐答案

如果在Tomcat中部署Web应用程序,则在部署过程中,Tomcat将复制$ CATALINA_HOME/conf/中的META-INF/context.xml文件.上下文将可用于您的应用程序.请记住,如果因为不希望从应用程序中删除context.xml,则还必须从$ CATALINA_HOME/conf/

If you deploy a Web application in Tomcat, in the deployment process, Tomcat will copy the META-INF/context.xml file in $CATALINA_HOME/conf/ so the context will be available for your application. Take in mind, that if you remove context.xml from you application because you dont want it, you also have to delete it manually from $CATALINA_HOME/conf/

如果您已编辑server.xml以包含dababase资源,并且在删除context.xml时不起作用,则可能是因为在server.xml中定义资源时出错了

If you have edited the server.xml for including your dababase resource and is not working when you remove context.xml it could be because you made some mistake defining your resourde in server.xml

已更新:

当资源位于server.xml中时,在上下文中,您应该引用server.xml中的全局资源.例如:

When resource is in server.xml, in context you should make a reference to global resource in server.xml. For example:

<Context crossContext="true" reloadable="true" >
    <ResourceLink name="jdbc/myApp" type="javax.sql.DataSource" global="jdbc/myApp" />
</Context>

这篇关于春季在Tomcat中使用JNDI ...为什么我的项目中需要META-INF/context.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆