Tomcat6 ignores META-INF/context.xml
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 cont开发者_如何转开发ent 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.xmlContent 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
I've got your code working IF I delete the <Context>
from the server.xml and define it only in the META-INF/context.xml
It doesn't work when the <Context>
is defined in both places.
Secondly, change your type to String, instead of Integer
<Environment name="tt" value="this is a string" type="java.lang.String"></Environment>
</Context>
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.
精彩评论