惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
F
Fortinet All Blogs
J
Java Code Geeks
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
M
MIT News - Artificial intelligence
腾讯CDC
Last Week in AI
Last Week in AI
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
博客园 - 叶小钗
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
L
LangChain Blog
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - daniel-shen

精通EJB-概述 硬件基础知识大全 教程:关于XMLBeans的初步 在客户端进行xslt对xml的xuan渲染 jaxp笔记2007-4-17 6.ZK用户接口标记语言 5.事件的监听和处理 - daniel-shen - 博客园 4.组件的生命周期 3.zk体系结构 "tomcat启动分析"文章读后笔记 jdk5.0 范型说明 java 数组反射例子 HTML小技巧 MessageFormat初步 ResourceBundle 与locale的使用 jni中关于dll的装载问题 java线程-消费者vs生产者 HttpSessionBindingListener实现与应用 用Java Servlets 2.4实现过滤
加和不加java:comp/env/前缀有什么区别?
daniel-shen · 2006-10-24 · via 博客园 - daniel-shen

java:comp/env是标准的J2EE环境查找规则
使用这种方式必须做一次环境名到JNDI名的映射
这种隔离使得在写程序时不必关注真正的JNDI名字
其实说白了跟把JNDI名放到配置文件里是一样的
用法如下,如把java:comp/env/my/datasource映射到
my.ora.dataource

web.xml
<resource-ref>
<res-ref-name>my/datasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER<res-auth>
</resource-ref>

weblogic.xml
<reference-descriptor>
--<resource-description>
----<res-ref-name>my/datasource</res-ref-name>
----<jndi-name>my.ora.dataource</jndi-name>

而在streamGallay中,ConfDbConnect中也用到了
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
ds = (DataSource) envContext.lookup(ConfSysInfo.dataBase);
对应的tomcat下应用的web.xml中如下:
<resource-ref>
  <description>DB Connection</description>
  <res-ref-name>jdbc/postgresql</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>