java:comp / env未绑定 [英] java:comp/env is not bound

查看:330
本文介绍了java:comp / env未绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在$ CATALINA_HOME / lib目录中有一些库来处理一些系统/数据库身份验证。这些文件foo.jar包含一个扩展了

I currently have a few libraries in my $CATALINA_HOME/lib directory to handle some system/DB authentication. One of those files foo.jar contains a class that extends

org.apache.catalina.realm.DataSourceRealm

并用于身份验证。该文件需要访问我存储在server.xml中的一些属性,但是,尝试访问它时出现错误。代码段如下

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. 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) {} 

有什么想法吗?

推荐答案

您还需要在context.xml中为您的应用提供关联的ResourceLink。例如,如果您的Web应用程序名为foo,则应该有一个名为 conf / Catalina / localhost / foo.xml 的文件,并带有

You also need to have the associated ResourceLink in the context.xml for your app. For example, if your webapp is named foo, there should be a file called conf/Catalina/localhost/foo.xml with a

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

<Context antiJARLocking="true">
    <ResourceLink name="property" 
        type="classname" 
        global="propertyNameInGlobalNamingResources" />  
    ...
</Context>

如果包含 META-INF / context.xml 在您的war文件中具有这些链接,tomcat会在首次部署应用程序时将其复制到 conf / Catalina / localhost / foo.xml 在此之后的任何时间,因为您打算在那里进行更改并能够再次进行部署而不会破坏自定义)

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)

这篇关于java:comp / env未绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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