Jetty中使用JNDI设置环境变量

阅读更多

【目的】

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  :
	
	
	 
	
	

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

 

【解决方案】

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


	
		
		wsPathPhq
		http://localhost:8080/cis2_ws/
		true
	
...

 

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

Binding Objects into Jetty JNDI

You can bind four types of object into Jetty JNDI:

  • An ordinary POJO instance.
  • A java.naming.Reference instance.
  • An object instance that implements the java.naming.Referenceable interface.
  • A link between a name as referenced in web.xml and as referenced in the environment.

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

 class=type of naming entry>
  >scope>
  >name to bind as>
  >the object to bind>
>

Defining Naming Entries

The type of naming entry can be:

  • "org.eclipse.jetty.plus.jndi.EnvEntry" for 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

 

你可能感兴趣的:(Jetty中使用JNDI设置环境变量)