基于Spring的JNDI方式请求EJB服务

         开发中有一个新项目需要调用现存的EJB服务,新项目有Spring容器,参考文档后使用JNDI方式请求EJB服务。解决思路如下。

 

         首先是配置JNDI服务的属性文件,application.local.properties。

#########################################################
# JNDI 
#########################################################
naming.initial=org.jnp.interfaces.NamingContextFactory
naming.pkgs=org.jboss.naming:org.jnp.interfaces
naming.root=sg-service-ear-1.0.0-M3-SNAPSHOT
naming.url=jnp://172.16.0.55:1099

         naming.root是ejb发布后的服务名。naming.url是EJB服务地址,1099是默认端口。

 

         在Spring配置文件applicationContext.xml中引入该属性文件

	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreResourceNotFound" value="true" />
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>
				<!-- 本地开发 -->
				<value>classpath:application.local.properties</value>
				<!-- 服务器环境 -->
				<value>file:/var/mms/application.server.properties</value>
			</list>
		</property>
	</bean>

         加入一个配置文件管理商业接口 modules-remote.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="
		   http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/jee 
           http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
           http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util-2.5.xsd">
	<util:map id="jndiEnv">
		<entry key="java.naming.factory.initial" value="${naming.initial}" />
		<entry key="java.naming.factory.url.pkgs" value="${naming.pkgs}" />
		<entry key="java.naming.provider.url" value="${naming.url}" />
	</util:map>
	<jee:remote-slsb id="orderInfoService"
		jndi-name="${naming.root}/OrderInfoServiceBean/remote"
		business-interface="com.test.trade.service.OrderInfoService"
		resource-ref="true" cache-home="true" lookup-home-on-startup="false"
		environment-ref="jndiEnv">
	</jee:remote-slsb>
</beans>

           OrderInfoService是一个商业接口,OrderInfoServiceBean是一个具体的实现。

           开发中注入这个远程接口即可

 

 

        private OrderInfoService _orderInfoService;

	@Autowired
	public void setOrderInfoService(OrderInfoService orderInfoService) {
		_orderInfoService = orderInfoService;
	}

         为了应用以上服务需要导入一些Jboss的jar包,因为没有使用maven,手动引入以下jar包

         jbossall-client.jar
         jboss-aspect-library-jdk50.jar
         jboss-ejb3x.jar

         以上jar在{JBOSS_ROOT}/client 下都可以找到。

 

         have fun fellows.   

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值