[英]java:comp/env is not bound
I currently have a few libraries in my $CATALINA_HOME/lib directory to handle some system/DB authentication. 我目前在$ CATALINA_HOME / lib目录中有一些库来处理一些系统/数据库身份验证。 One of those files foo.jar contains a class that extends
这些文件foo.jar之一包含一个扩展的类
org.apache.catalina.realm.DataSourceRealm
and is being used to authentication. 并已用于身份验证。 This file needs to access a few properties that I'm storing in server.xml However, when attempting to access it I'm getting an error.
该文件需要访问存储在server.xml中的一些属性。但是,尝试访问该文件时出现错误。 The segment of code is as follows
代码段如下
try{
Context ctx = new InitialContext();
Context envCtx = (Context)ctx.lookup("java:comp/env");
String property = (String)envCtx.lookup("property");
} catch(Exception ex) {}
Any ideas? 有任何想法吗?
You also need to have the associated ResourceLink in the context.xml for your app. 您还需要在您的应用的context.xml中具有关联的ResourceLink。 For example, if your webapp is named foo, there should be a file called
conf/Catalina/localhost/foo.xml
with a 例如,如果您的Web应用程序名为foo,则应该有一个名为
conf/Catalina/localhost/foo.xml
其中包含
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Context>
<Context antiJARLocking="true">
<ResourceLink name="property"
type="classname"
global="propertyNameInGlobalNamingResources" />
...
</Context>
If you include a META-INF/context.xml
with these links in your war file, tomcat will copy it out to the conf/Catalina/localhost/foo.xml
the first time the app is deployed (though not any time after that as you are intended to make changes there and be able to deploy again without clobbering customization) 如果您在war文件中包含带有这些链接的
META-INF/context.xml
,则tomcat会在首次部署应用程序时将其复制到conf/Catalina/localhost/foo.xml
(尽管之后没有任何时间)您打算在那里进行更改并能够再次部署而不会破坏自定义)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.