java:comp/env/ 的作用是什么?
我只是花了太多时间试图找出连接某些 JNDI 工厂 bean 时出现的一些错误。问题结果是,而不是这个...
<bean id="someId" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/loc"/>
</bean>
我实际上写了这个...
<bean id="someId" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/loc"/>
</bean>
我推断 java:comp/env/ 可能引用了一些环境变量并使其最终,我的上下文文件被查看。唯一的区别是 java:comp/env/
。从专家嘴里说出来,那有什么作用呢?
如果值中没有 java:comp/env/
前缀,我会收到一条错误消息,指出“Name jdbc is not bond in this Context”。
I just spent too much time of my day trying to figure out some errors when hooking up some JNDI factory bean. The problem turned out to be that instead of this...
<bean id="someId" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/loc"/>
</bean>
I had actually written this...
<bean id="someId" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/loc"/>
</bean>
I infer that the java:comp/env/
perhaps references some environment variable and makes it so that, ultimately, my context file is looked at. The only difference is java:comp/env/
. From an expert's mouth, what does that do?
Without the java:comp/env/
prefix in the value, I would get an error that said "Name jdbc is not bound in this Context".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
引用 https://web.archive.org/web/20140227201242/http://v1.dione.zcu.cz/java/docs/jndi-1.2/tutorial/beyond/misc/policy.html< /a>
因此,您从 spring 或 Tomcat 上下文描述符进行的绑定默认位于 java:comp/env/ 下。 例如
,如果您的配置是:
那么您可以直接使用: 访问它
,或者您可以进行中间步骤因此您不必为检索的每个资源指定“java:comp/env”:
Quoting https://web.archive.org/web/20140227201242/http://v1.dione.zcu.cz/java/docs/jndi-1.2/tutorial/beyond/misc/policy.html
So the binding you did from spring or, for example, from a tomcat context descriptor go by default under java:comp/env/
For example, if your configuration is:
Then you can access it directly using:
or you could make an intermediate step so you don't have to specify "java:comp/env" for every resource you retrieve:
JndiObjectFactoryBean
还有一个属性resourceRef
,当设置为true
时,用于自动在前面添加字符串java:comp/ env/
(如果尚不存在)。There is also a property
resourceRef
ofJndiObjectFactoryBean
that is, when set totrue
, used to automatically prepend the stringjava:comp/env/
if it is not already present.经过多次尝试并深入 Tomcat 的源代码,我发现简单的属性 useNaming="false" 成功了!!现在 Tomcat 解析名称 java:/liferay 而不是 java:comp/env/liferay
After several attempts and going deep in Tomcat's source code I found out that the simple property useNaming="false" did the trick!! Now Tomcat resolves names java:/liferay instead of java:comp/env/liferay