Spring与EJB的整合(关键部分)

来源:互联网 发布:手机淘宝推广平台 编辑:程序博客网 时间:2024/05/22 19:38
  Spring支持EJB能够大致的分成两类:访问和实现。Spring中内置了三种抽象类作为EJB Bean的基类,相对应于EJB无状态Bean、有状态Bean和消息Bean,它们分别为AbstractStatelessSessionBeanAbstractStatefulSessionBeanAbstractMessageDrivenBean。运用时只要以它们为父类,作相应的扩展即可。

    下面将介绍在Spring的配置文件ApplicationContext.xml中管理EJB的Bean。

   Spring容器负责管理JavaBean和SessonBean,Spring的ApplicationContext以Framework的方式提供BeanFactory的所有功能。使用ApplicationContext,可以让系统加载你的Bean,当程序中需要用到Bean时,它就自动生成相应的Bean对象以供使用。本架构中使用Spring容器来管理EJB的Session Bean。applicationContext.xml配置文件如下:

   

       <bean id="propertyConfigurer"

       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

            <property name="locations">

                  <list>

                        <value>WEB-INF/jboss.properties</value>

                  </list>

            </property>

       </bean>

      <util:properties id="jndienvironment" location="WEB-INF/jndi.properties"/>

      <jee:remote-slsb id="ldUserUIDAO" jndi-name="LDUserUI/remote"

                  business-interface="com.cugb.ejb.userManage.dao.LDUserUIDAORemote"

                             resource-ref="true" environment-ref="jndienvironment" /> 

    Spring可以通过jee:local-slsb注入本地的Session Bean,通过jee:remote-slsb注入远程的Session Bean,也可以通过jee:jndi-lookup直接指定JNDI的方式注入Session Bean。

    如果客户端和服务器不在同一个Java VM上,那么在客户端必须提供一个jndi.properties文件告诉客户端进行有关JNDI命名服务的信息,并且把这个文件所在目录设定到环境。jndi.properties配置如下:

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

      java.naming.provider.url=localhost:1099

原创粉丝点击