1-Hivemind和Spring的比較

在如下方面HiveMind優於Spring:
  
  * HiveMind強制針對接口編程;
  
  * HiveMind使用module概念來分組治理service,利於並行和迭代開發;
  
  * HiveMind使用的配置文件格式更清楚簡明,將接口和實現統一定義成1個service,而Spring可能要定義好幾個bean元素;
  
  * 在增加或移去interceptor時,HiveMind只要修改1行配置文件,而Spring至少要修改兩個bean元素;
          <service-point id="Adder" interface="org.apache.hivemind.examples.Adder">
             <create-instance class="org.apache.hivemind.examples.impl.AdderImpl"/>
             <interceptor service-id="hivemind.LoggingInterceptor"/>
        </service-point>

這裏又發現了一個比Spring要方便的地方,interceptor可以直接定義在(我都不知道怎麼說了,用Bean還是service-point?) Component的內部,用Spring的話還得另外建立一個新的Bean,然後指定Advice的作用域,如果系統中只有一兩處需要的話,多一個 Bean的配置顯得有點不雅。記得xWork也是這樣定義interceptor的。
  
  * 在定義interceptor時,HiveMind採用Javassist類庫,性能優於Spring採用的JDK proxy。

在如下方面Spring優於HiveMind:
  
  * Spring的AOP框架較爲成熟,編寫interceptor的難度較低。
  
  * Spring內建和Hibernate的集成,HiveMind尚未內建該集成。
  
  * Spring的transaction management支持各種transaction API,如JDBC、JDO、JTA等等。


How to configure declarative transaction management?
  
  Spring: 採用AOP。
  
  <bean id="petStoreTarget" class="org.springframework.samples.jpetstore.dom
  
  ain.logic.PetStoreImpl">
  <property name="accountDao"><ref bean="accountDao"/></property>
  <!-- Other dependencies omitted -->
  </bean>
  
  <bean id="petStore"
  class="org.springframework.transaction.interceptor.TransactionProxyFac
  
  toryBean">
  <property name="transactionManager"><ref bean="transactionManager"/></
  
  property>
  <property name="target"><ref local="petStoreTarget"/></property>
  <property name="transactionAttributes">
  <props>
  <prop key="insert*">PROPAGATION_REQUIRED</prop>
  <prop key="update*">PROPAGATION_REQUIRED</prop>
  <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
  </props>
  </property>
  </bean>
  
  HiveMind: 沒有內建支持。我自行開發了一個TransactionInterceptor
  <interceptor service-id="TransactionInterceptor">
  <include method="add*"/>
  </interceptor>
  
  Comments:
  在Spring中假如需要混合使用TransactionInterceptor和其他Interceptor,需要定義多個bean。增大了維護成本。
  Spring支持JTA等各種Transaction manager。
  HiveMind配置文件更加清楚簡明。但不沒有提供JTA集成很致命。






 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章