本站不再更新,欢迎光临 java开发技术网
随笔-230  评论-230  文章-8  trackbacks-0

service 服务居必须使用面向接口的方式编程

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
    
<!-- spring+hibernate 基本配置 -->
    
<bean id="placeholderConfig"
        class
="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        
<property name="location">
            
<value>classpath:spring.properties</value>
        
</property>
    
</bean>
    
    
<bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="hibernateProperties">
            
<props>
    
                
<prop key="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</prop>
                
<prop key="hibernate.show_sql">true</prop>
                 
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
                
<prop key="hibernate.proxool.xml">proxool.xml</prop>
                
<prop key="hibernate.proxool.pool_alias">xhibernate</prop>
                
<prop key="hibernate.jdbc.batch_size">25</prop>
                
<prop key="hibernate.jdbc.fetch_size">50</prop>
                
<prop key="hibernate.connection.release_mode">after_transaction</prop>
            
</props>
        
</property>
        
<property name="mappingResources">
            
<list>

                
<value>com/easylotto/lottobar/domain/Demo.hbm.xml</value>
            
            
</list>
        
</property>
    
</bean>
    
<!-- spring 事务配置 -->
    
<bean id="transactionManager"
        class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
        
<property name="sessionFactory" ref="sessionFactory" />
    
</bean>
    
    
<bean id="baseTransactionProxy"
        class
="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
        abstract
="true">
        
<property name="transactionManager">
            
<ref bean="transactionManager" />
        
</property>
        
<property name="transactionAttributes">
            
<props>
                
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
            
</props>
        
</property>
    
</bean>
    
<!-- 系统常常 -->
    
<bean id="commandHandler" class="java.lang.String">
        
<constructor-arg value="com.easylotto.lottobar.framework.BarServerCommandHandler"/>
    
</bean>
    
<bean id="clientData" class="java.lang.String">
        
<constructor-arg value="com.easylotto.lottobar.bean.SocketClientLoginInfoEntity"/>
    
</bean>
    
<bean id="serverPort" class="java.lang.String">
        
<constructor-arg value="4100"/>
    
</bean>
    
<bean id="serverName" class="java.lang.String">
        
<constructor-arg value="17lottoBarServer"/>
    
</bean>
    
    
<!-- VO PO 的父类 -->
    
<bean id="baseEntity"  class="com.easylotto.lottobar.bean.BaseEntity"  abstract="true" />
    
<!-- 命令VO -->
    
<bean id="reqCommandVO" class="com.easylotto.lottobar.bean.ReqCommandVO" parent="baseEntity"/>
    
    

    
<!-- 测试例子 -->
    
<bean id="demoService"  parent="baseTransactionProxy">
        
<property name="target">
            
<bean class="com.easylotto.lottobar.barserver.service.DemoService"
                autowire
="byName" />
        
</property>
    
</bean>
    
    
<!-- 命令解析 -->
    
<bean id="commandParse" class="com.easylotto.lottobar.framework.CommandParse" />
    
<!-- 命令融器 -->
    
<bean id="commandContainer" class="com.easylotto.lottobar.framework.CommandContainer" >
        
<property name="commandMap">
            
<map>
                
<entry key="test" value-ref="demoService" />
                
            
</map>
        
</property>
    
</bean>
    
<!-- 服务运行 -->
    
<bean id="barServer" class="com.easylotto.lottobar.framework.BarServer">
        
<property name="commandHandler">
            
<ref bean="commandHandler"/>
        
</property>
        
<property name="clientData">
            
<ref bean="clientData"/>
        
</property>
        
<property name="serverPort">
            
<ref bean="serverPort"/>
        
</property>
        
<property name="serverName">
            
<ref bean="serverName"/>
        
</property>    
    
</bean>
    
    
<bean id="demoDAO" class="com.easylotto.lottobar.dao.DemoDAO" >
        
<property name="sessionFactory">
            
<ref bean="sessionFactory" />
        
</property>
    
</bean>
    
</beans>    

如果采用spring声明式管理后,直接调用DAO的方式并能不保存数据
  DemoDAO demoDAO=(DemoDAO)cpac.getBean("demoDAO");
  Demo d=new Demo();
  d.setName("小pei");
  d.setAge(558);
  demoDAO.save(d);
这是为什么??同事说加上
<bean id="userInfoDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userInfoDAOImpl" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
DAO也采用代理的方式就可以不跟过Service层直接能操作DB,我想应该是这样,但没试用

通过spring 的ApplicationContext获取服务实例时只能使用接口如
IService ds =(IService)cpac.getBean("demoService");
而不是能是对象!!!

乱,仅做个人笔记

posted on 2008-02-29 16:26 有猫相伴的日子 阅读(599) 评论(0)  编辑  收藏 所属分类: ibatis/hibernate/持久层技术

只有注册用户登录后才能发表评论。


网站导航:
 
本站不再更新,欢迎光临 java开发技术网