structs2+spring+ibatis

Struts2.0和webwork2以上版本有很多类似的特性,前面已写了一篇有关webwork+spring+ibatis的拙作,为了省去罗嗦,在本篇文章中仅就对前篇文章未涉及到特性做些说明,并写了一则小例子,我也是刚学这方面的东东,但愿本文能对初学者能有些帮助:).

下面是有关该小例子的配置文件.
applicationContext.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"
  xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"
  default-lazy-init="true" default-autowire="no" default-dependency-check="none">
  
  <bean id="configurer"
  	class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  	<property name="locations" value="classpath:/config/jdbc.properties"></property>
  </bean>
  <!-- JDBC DataSource -->
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClass}" />
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="user" value="${jdbc.user}" />
    <property name="password" value="${jdbc.password}" />
    <property name="initialPoolSize" value="2" />
    <property name="minPoolSize" value="2" />
    <property name="maxPoolSize" value="10" />
    <property name="acquireIncrement" value="2" />
    <property name="maxIdleTime" value="2" />
    <property name="maxStatements" value="10" />
    <property name="autoCommitOnClose" value="false" />
  </bean>
  <bean id="inject.Processor" class="com.chinasunzone.xbase.core.spring.InjectProcessor" lazy-init="false">
  </bean>
</beans>



applicationContext-ibatis.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"
  xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"
  default-lazy-init="true" default-autowire="no" default-dependency-check="none">
  <bean id="lazyDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
    <property name="targetDataSource">
        <ref bean="dataSource"/>
    </property>
  </bean>
  <bean id="transactionManager"
  	class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  	<property name="dataSource">
  		<ref local="lazyDataSource"></ref>
  	</property>
  </bean>
  <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionAttributeSource">
      <bean id="transactionAttributeSource"
        class="com.ssi.xbase.AnnotationTransactionAttributeSource">
        <property name="defaultRollbackFor" value="java.lang.Throwable" />
      </bean>
    </property>
    <property name="transactionManager">
      <ref local="transactionManager" />
    </property>
  </bean>
  <bean id="sqlMapClient"
  	class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  	<property name="configLocation">
  		<value>classpath:/config/SqlMapConfig.xml</value>
  	</property>
  </bean>
  <bean id="userDao" class="com.wwsi.dao.impl.UserDao">
        <property name="dataSource">
            <ref local="lazyDataSource"/>
        </property>
        <property name="sqlMapClient">
            <ref local="sqlMapClient"/>
        </property>
  </bean>

  <!-- Transaction AOP-Config For Service -->
  <aop:config>
    <aop:pointcut id="serviceTxPointcut" expression="execution(* com.ssi.service..I*Service.*(..))" />
    <aop:advisor pointcut-ref="serviceTxPointcut" advice-ref="transactionInterceptor" order="1000" />
  </aop:config>
</beans>

applicationContext-service.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-lazy-init="false">
  <bean id="userService" class="com.ssi.service.impl.UserService">
  </bean>
</beans>

application-web.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-lazy-init="false">
  <bean id="dispatchAction"
		class="com.opensymphony.xwork2.ActionSupport" singleton="false">
  </bean>
  <bean id="userAction" class="com.ssi.action.UserAction"
  	singleton="false">
  </bean>
</beans>
  



只上传了除JAR包以外的程序部分.另附上所需JAR的截图,以便对照下载

你可能感兴趣的:(java,spring,xml,bean,ibatis)