struts2+spring2+hibernate3:连接池采用proxool

1、web.xml配置,配置lisenter和需要加载的参数文件context-param。

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter>
   <filter-name>struts-cleanup</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
   <filter-name>struts-cleanup</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <session-config>
   <session-timeout>30</session-timeout>
  </session-config>
  <context-param><!--spring的bean的配置文件位置-->
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/config/applicationContext.xml</param-value>
  </context-param>
  <listener><!--启动时候加载spring的配置bean-->
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

2、struts.xml配置,这里配置spring的属性。
<struts>
 <!--添加constant属性配置,表示对象交由spring处理-->  
 <constant name="struts.objectFactory" value="spring" /> 
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />

    <include file="example.xml"/>

    <!-- Add packages here -->

</struts>
example.xml内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="sample" extends="struts-default">

        <action name="Login" class="Login"><!--class和spring的bean配置applicationContext.xml的bean配置一致-->
            <result>list.jsp</result>
            <result name="show">list.jsp</result>
        </action>
       
        <!-- Add actions here -->
    </package>
</struts>

3、applicationContext.xml配置,这里配置bean的注入和sessionFactory 以及aop等:
<?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:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

 <bean name="Login" class="com.action.login.Login">
  <property name="loginBo"><ref bean="loginBo"/></property>
 </bean>
 <bean name="loginBo" class="com.action.login.LoginBo">
  <property name="loginDao"><ref bean="loginDao"/></property>
 </bean>
 <bean name="loginDao" class="com.action.login.LoginDao">
  <property name="baseDao"><ref bean="baseDao"/></property>
 </bean>
 
 <!-- 以下是公共的bean配置 -->
 <bean name="baseDao" class="com.dao.BaseDao">
  <property name="sessionFactory"><ref bean="mySessionFactory"/></property>
 </bean>
 <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  <property name="mappingResources">    
   <list>    
    <value>com/bo/hbm/Maxl_tt.hbm.xml</value>    
   </list> 
  </property>  
  <property name="hibernateProperties">    
   <props>      
    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>     
    <prop key="hibernate.show_sql">false</prop>      
    <prop key="hibernate.proxool.xml">../config/proxool.xml</prop>      
    <prop key="hibernate.proxool.pool_alias">s2ssample</prop>    
   </props> 
  </property>
 </bean> <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
 <bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
     <property name="sessionFactory">
          <ref local="mySessionFactory"/>
      </property>  
 </bean>
 
 <!-- log AOP -->
  <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
         <property name="beanNames">  
             <list>  
                 <value>*Action</value>
                 <value>*Bo</value>
                 <value>*Dao</value>
             </list>  
         </property>  
         <property name="interceptorNames">  
             <list>  
                 <value>logAdvice</value>  
             </list>  
         </property>  
     </bean>  
 <bean id="logAdvice" name="logAdvice" class="com.aop.LogAdvice"></bean>
 <!-- log AOP -->
</beans>

4、proxool.xml配置:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
  <proxool>
    <alias>s2ssample</alias>
    <driver-url>jdbc:oracle:thin:@100.40.5.39:1521:oracle</driver-url>
    <driver-class>oracle.jdbc.OracleDriver</driver-class>
    <driver-properties>
      <property name="user" value="test"/>
      <property name="password" value="test"/>
    </driver-properties>
    <maximum-connection-count>20</maximum-connection-count>
    <house-keeping-test-sql>select sysdate from dual</house-keeping-test-sql>
  </proxool>
</something-else-entirely>

你可能感兴趣的:(spring,AOP,bean,Hibernate,struts)