<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    Spring3 and EJB Integration(I)EJB Client

    Spring3 and EJB Integration(I)EJB Client
    I used EJB client to call EJB stateless bean, I found it is waste time to lookup the stateless bean every time.
    So I tried to use spring to get singleton stub from EJB stateless bean.
    The sample project are in easyaxis2proxy,easyrestproxy,easyjpa,easyejb.
    We can configure that in Remote/Local way, you can choose that from comment/uncomment the codes I mentioned here.

    1. Spring configuration file
    local-ejb-context.xml:
    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx
    ="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation
    ="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
               http://www.springframework.org/schema/tx 
               http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    "
    > 
    <bean id="jndiTemplate" 
            class
    ="org.springframework.jndi.JndiTemplate"> 
            
    <property name="environment"> 
                
    <props> 
                    
    <prop key="java.naming.provider.url"> 
                        ${java.naming.provider.url} 
                    
    </prop> 
                    
    <prop key="java.naming.factory.initial"> 
                        ${java.naming.factory.initial} 
                    
    </prop> 
                    
    <prop key="java.naming.factory.url.pkgs"> 
                        ${java.naming.factory.url.pkgs} 
                    
    </prop> 
                
    </props> 
            
    </property> 
        
    </bean> 
    <bean id="userServiceLocal" 
    class
    ="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean"> 
    <property name="jndiTemplate" ref="jndiTemplate" /> 
    <property name="jndiName" value="easyejb/UserServiceLocal" /> 
    <property name="businessInterface" 
    value
    ="com.sillycat.core.webservice.interfaces.UserServiceLocal" /> 
    </bean> 
    </beans> 

    remote-ejb-context.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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx
    ="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation
    ="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    "
    >

    <bean id="jndiTemplate"
    class
    ="org.springframework.jndi.JndiTemplate">
    <property name="environment">
    <props>
    <prop key="java.naming.provider.url">
    ${java.naming.provider.url}
    </prop>
    <prop key="java.naming.factory.initial">
    ${java.naming.factory.initial}
    </prop>
    <prop key="java.naming.factory.url.pkgs">
    ${java.naming.factory.url.pkgs}
    </prop>
    </props>
    </property>
    </bean>
    <bean id="userServiceRemote" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="easyejb/UserService" />
    <property name="businessInterface"
    value
    ="com.sillycat.core.webservice.interfaces.UserService" />
    </bean>
    </beans>

    We can choose use Remote/Local from the main-context.xml

    <import resource="classpath:resource-context.xml" />
    <import resource="classpath:core-context.xml" />
    <import resource="classpath:dao-context.xml" />
    <import resource="classpath:manager-context.xml" />
    <!--
    <import resource="classpath:local-ejb-context.xml" />
    <import resource="classpath:remote-ejb-context.xml" />
    -->
    <import resource="classpath:local-ejb-context.xml" />

    <import resource="classpath:controller-easyrestproxy-context.xml" />
    <import resource="classpath:restclient-context.xml" />

    <!--My manager spring configuration to call EJB -->
    <bean id="personManager" class="com.sillycat.easyjpa.manager.PersonManagerImpl" >
    <property name="personDAO" ref="personDAO" />
    <!--
    <property name="userServiceLocal" ref="userServiceLocal" />
    <property name="userServiceRemote" ref="userServiceRemote" />
    -->
    <property name="userServiceLocal" ref="userServiceLocal" />
    </bean>

    2. The properties file config.properties:

    ###########################################
    # EJB configuration
    ###########################################
    java.naming.factory.initial
    =org.jnp.interfaces.NamingContextFactory
    java.naming.factory.url.pkgs
    =org.jboss.naming:org.jnp.interfaces
    java.naming.provider.url
    =localhost:1099

    3. My Manager java source:

    package com.sillycat.easyjpa.manager;
    import java.util.List;
    import com.sillycat.core.webservice.interfaces.UserServiceLocal;
    import com.sillycat.core.webservice.model.IUser;
    import com.sillycat.easyjpa.dao.PersonDAO;
    import com.sillycat.easyjpa.model.Person;
    public class PersonManagerImpl implements PersonManager
    {
    PersonDAO personDAO;
    UserServiceLocal userServiceLocal;
    // UserService userServiceRemote;
    public List<Person> getAll()
    {
    return personDAO.getAll();
    }

    public Person get(Integer id)
    {
    IUser iuser
    = userServiceLocal.get(Integer.valueOf(1));
    // IUser iuser = userServiceRemote.get(Integer.valueOf(1));
    Person p = personDAO.get(id);
    p.setName(iuser.getEmail());
    return p;
    }

    public void save(Person person)
    {
    if (person != null && person.getId() != null)
    {
    personDAO.update(person);
    }

    else
    {
    personDAO.insert(person);
    }

    }

    public void updateName(Person person)
    {
    if (person != null && person.getId() != null)
    {
    personDAO.updateName(person.getName(), person.getId());
    }

    }

    public void delete(Integer id)
    {
    personDAO.delete(id);
    }

    public void setPersonDAO(PersonDAO personDAO)
    {
    this.personDAO = personDAO;
    }

    // public void setUserServiceRemote(UserService userServiceRemote)
    // {
    // this.userServiceRemote = userServiceRemote;
    // }
    public void setUserServiceLocal(UserServiceLocal userServiceLocal)
    {
    this.userServiceLocal = userServiceLocal;
    }

    }


    4. We can deploy these packages to JBOSS, and run the axis2 testcase or rest testcase to verify that.

    posted on 2011-11-24 21:54 paulwong 閱讀(535) 評論(0)  編輯  收藏 所屬分類: EJB3

    主站蜘蛛池模板: 久久久久国产精品免费网站| 精品亚洲国产成AV人片传媒| 久草在视频免费福利| 中国一级特黄的片子免费 | 国产精品酒店视频免费看| 久久午夜伦鲁片免费无码| xxxxxx日本处大片免费看| 亚洲日韩AV无码一区二区三区人| 亚洲AV日韩精品久久久久久| 亚洲国产成人久久一区WWW| 四虎永久在线精品免费网址 | 久视频精品免费观看99| 国产做国产爱免费视频| 无忧传媒视频免费观看入口| 99亚偷拍自图区亚洲| 亚洲激情校园春色| 夜夜亚洲天天久久| 亚洲av日韩av高潮潮喷无码| 国产成人综合亚洲AV第一页| 免费一级特黄特色大片在线观看| 欧美a级成人网站免费| 日本人的色道免费网站| 免费国产黄网站在线观看可以下载 | 亚洲永久网址在线观看| 亚洲国产成a人v在线观看| 久久国产亚洲高清观看| 亚洲丁香色婷婷综合欲色啪| 亚洲s色大片在线观看| 国产亚洲一区二区在线观看| 亚洲午夜久久久久妓女影院| 久久精品国产精品亚洲| 久久亚洲国产精品五月天婷| 免费一级特黄特色大片在线| 免费人成视频x8x8入口| www.91亚洲| 综合亚洲伊人午夜网| 亚洲日韩精品无码一区二区三区| 亚洲综合伊人久久大杳蕉| 国产亚洲色婷婷久久99精品| 亚洲大尺度无码无码专区| 亚洲精品综合一二三区在线|