简体   繁体   English

java:comp / env未绑定

[英]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.

相关问题 javax.naming.NameNotFoundException:名称 [comp/env] 未绑定在此上下文中。 无法找到 java 调度程序的 [comp] 错误 - javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [comp] error with java scheduler 在java中设置属性:comp / env? - Setting a property in java:comp/env? 什么是java:comp / env作用域规则? - What is java:comp/env scope rules? InitialContext 查找(“java:comp/env”)失败 - InitialContext lookup(“java:comp/env”) fails 在上下文“java:”中找不到 comp/env/pool? - comp/env/pool not found in context “java:”? Tomcat服务器异常-此上下文中未绑定java:comp - Tomcat server exception - java:comp is not bound in this Context javax.naming.NameNotFoundException:名称[comp / env]在此上下文中未绑定。 在Tomcat中找不到[comp] - javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [comp] in Tomcat Java EE异常:此上下文中未绑定名称java:comp - Java EE Exception: Name java:comp is not bound in this Context Spring应用程序侦听器-ContextRefreshedEvent java:comp / env / jdbc / db未找到 - Spring Application Listener - ContextRefreshedEvent java:comp/env/jdbc/db not found glassfish-4 + spring jndi名称java:comp / env / jdbc / - glassfish-4 + spring jndi name java:comp/env/jdbc/
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM