在项目中使用Spring RMI现在紧急做下代码级别的记录方便以后使用。
服务器配置项:
<!-- 抽象的session工厂--> <bean id="xxxSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name="dataSource" ref="dataSource"/> <property name="mappingResources"> <list> <value>com/xx/xxxx/business/entity/xxxxxxx.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="show_sql">false</prop> <prop key="hibernate.query.substitutions">true 'y', false 'n', yes 'y', no 'n'</prop> </props> </property> </bean>
//Spring声明式事务
<bean id="xxxTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="false"> <property name="sessionFactory"> <ref bean="xxxSessionFactory"/> </property> </bean>
<bean id="basePsmProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="false"> <property name="transactionManager"> <ref bean="xxxTransactionManager"/> </property> <property name="transactionAttributes"> <!-- 下面定义事务传播属性 --> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="change*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="do*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="list*">PROPAGATION_REQUIRES_NEW,readOnly</prop> <prop key="get*">PROPAGATION_REQUIRES_NEW,readOnly</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> </props> </property> </bean>
// bean配置项项 ------服务器端配置 //################################################################################# <bean id="moneyServiceImpl" parent="basePsmProxyTemplate"> <property name="target"> <bean class="com.langgelila.psm.rmi.impl.ProivideMoneyServiceImpl" /> </property> </bean> <bean id="ydMoneyRmi" class="org.springframework.remoting.rmi.RmiServiceExporter" > <property name="serviceName" value="moneyService"/> <property name="service" ref="moneyServiceImpl"/> <property name="serviceInterface" value="com.langgelila.psm.rmi.iface.ProivideMoneyService"/> <property name="registryPort" value="1302"/> </bean> //###########################客户端配置项###################################### <!-- 远程调用 --> <bean id="psmMoneyService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="${psmrmiip}"></property> <property name="serviceInterface" value="com.langgelila.psm.rmi.iface.ProivideMoneyService" /> <property name="lookupStubOnStartup" value="false" /> <property name="refreshStubOnConnectFailure" value="true" /> </bean>