Tomcat6 忽略 META-INF/context.xml
Tomcat6 一直忽略我的 META-INF/context.xml。当我尝试查找“tt”时,我不断收到“名称 tt 未在此上下文中绑定”(请参阅“详细信息”)。
当我将 META-INF/context.xml 的内容放入 server.xml 中的“context”标记内时,它就可以工作。我还检查了 $Tomcat-base/Catalina/localhost 为空,因此我的 META-INF/context.xml 未被覆盖。
详细信息:
Tomcat 版本:6.0.10
这是我的 Webroot 结构:
Webroot
|-META-INF
| |-context.xml
|
|-WEB-INF
|-web.xml
context.xml的内容:
<Context>
<Environment name="tt" value="this is a string" type="java.lang.String"></Environment>
</Context>
server.xml中该webroot的上下文标签:
<Context path="/test" docBase="E:\javaProjects\TestProject\Webroot" reloadable="true"></Context>
我的方式查找“tt”:
...
Context ic = new InitialContext();
Context ec = (Context) ic.lookup("java:comp/env");
String str = (String) ec.lookup("tt");
System.out.println("str is "+str);
我得到的错误:
javax.naming.NameNotFoundException: Name tt is not bound in this context
Tomcat6 keeps ignoring my META-INF/context.xml. I keep getting "Name tt is not bound in this Context" when I try to look up "tt" (please see 'details').
When I put the content of META-INF/context.xml inside the 'context' tag in server.xml, it works. I've also checked that $Tomcat-base/Catalina/localhost is empty, so my META-INF/context.xml is not overridden.
details:
Tomcat version: 6.0.10
Here's my Webroot structure:
Webroot
|-META-INF
| |-context.xml
|
|-WEB-INF
|-web.xml
Content of context.xml:
<Context>
<Environment name="tt" value="this is a string" type="java.lang.String"></Environment>
</Context>
Context tag of this webroot in server.xml:
<Context path="/test" docBase="E:\javaProjects\TestProject\Webroot" reloadable="true"></Context>
The way I look up for "tt":
...
Context ic = new InitialContext();
Context ec = (Context) ic.lookup("java:comp/env");
String str = (String) ec.lookup("tt");
System.out.println("str is "+str);
The error I get:
javax.naming.NameNotFoundException: Name tt is not bound in this context
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我从 server.xml 中删除
并仅在META-INF/context.xml 中定义它,您的代码就可以正常工作
当
在两个地方都定义时,它不起作用。其次,将类型更改为 String,而不是 Integer
I've got your code working IF I delete the
<Context>
from the server.xml and define it only in theMETA-INF/context.xml
It doesn't work when the
<Context>
is defined in both places.Secondly, change your type to String, instead of Integer
您不能在两个不同的文件中定义一台主机中的两个上下文,这是问题的根源。有关更多信息,请阅读这篇文章。
you cannot have two contexts in one host defined in two different files, that was the root of problem. For more info read this article.