Jetty中使用JNDI设置环境变量

2 篇文章 0 订阅

【目的】

Production使用WebSphere作为App Server,但主包方开发团队在Dev环境使用Tomcat binding to Eclipse,我更倾向于使用Mave Jetty Plugin——项目本身就是使用Maven进行依赖管理的!

 

【问题】

主包方开发团队要求在Tomcat的Server.xml中定义Naming Resource,用于访问WS-资源,如下:

 * - server.xml
 *  Add the following inside XML Tag <GlobalNamingResources> :
	<Environment name="wsPathPhq" override="false" type="java.lang.String" value="http://localhost:8080/cis2_ws/"/>
	<Environment name="wsPathNtn" override="false" type="java.lang.String" value="http://localhost:8080/cis2_ws/"/>
	<Environment name="defaultSite" override="false" type="java.lang.String" value="PHQ"/> <!-- PHQ or NTN -->
	<Environment name="uiOffShorePath" override="false" type="java.lang.String" value="http://localhost:8080/cis2_ui/"/>
	<Environment name="uiOffShoreName" override="false" type="java.lang.String" value="NTN"/>

然后在代码中使用javax.naming.InitialContext.lookup(String)进行查找。 但Jetty如何支持?

 

【解决方案】

在Jetty.xml中,加入如下部分:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
	<New class="org.eclipse.jetty.plus.jndi.EnvEntry">
		<Arg></Arg>
		<Arg>wsPathPhq</Arg>
		<Arg type="java.lang.String">http://localhost:8080/cis2_ws/</Arg>
		<Arg type="boolean">true</Arg>
	</New>
...

 

【参考文档】https://wiki.eclipse.org/Jetty/Feature/JNDI

Binding Objects into Jetty JNDI

You can bind four types of object into Jetty JNDI:

The binding for all of these object types follows the same pattern:

<New class=type of naming entry>
  <Arg>scope</Arg>
  <Arg>name to bind as</Arg>
  <Arg>the object to bind</Arg>
</New>
Defining Naming Entries

The type of naming entry can be:

  • "org.eclipse.jetty.plus.jndi.EnvEntry" for <env-entry>s.
  • "org.eclipse.jetty.plus.jndi.Resource" for all other type of resources.
  • "org.eclipse.jetty.plus.jndi.Transaction" for a JTA manager. For detailed information, see the Configuring XA Transactions section.
  • "org.eclipse.jetty.plus.jndi.Link" for link between a web.xml resource name and a NamingEntry. For more information, see the Configuring Links section.

You can define naming entries in three places:

  1. jetty.xml
  2. WEB-INF/jetty-env.xml
  3. context xml file

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值