SSH全註解-annotation詳細配置

  • web.xml的配置:
<!--Spring的裝載器  -->  
    <listener>   
      <listener-class>   
         org.springframework.web.context.ContextLoaderListener            
      </listener-class>   
    </listener>  
    <!--spring的應用上下文,這裏也能夠用classpath:appli...xml  -->  
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>/WEB-INF/applicationContext.xml</param-value>  
    </context-param>  
   
  <!-- struts2文件攔截器 -->     
          
    <filter>    
      <filter-name>struts2</filter-name>    
      <filter-class>xx.servlet.web.MyStrutsFilterDispatcher</filter-class>    
     <init-param>  
        <param-name>actionPackages</param-name>  
        <param-value>xx.bean,xx.dao,xx.quanxin.action</param-value>  
       </init-param>  
    </filter>    
    <filter-mapping>  
      <filter-name>struts2</filter-name>  
      <url-pattern>/*</url-pattern>  
    </filter-mapping>  

 

  • 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:tx="http://www.springframework.org/schema/tx"  
xmlns:aop="http://www.springframework.org/schema/aop"  
xmlns:context="http://www.springframework.org/schema/context"  
xsi:schemaLocation="  
  http://www.springframework.org/schema/aop    
  http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  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" default-autowire="byType">  
          
<SPAN style="WHITE-SPACE: pre">   <context:annotation-config/>  
    <context:component-scan base-package="*" />  
      
    <aop:aspectj-autoproxy />   
  
        <tx:annotation-driven transaction-manager="transactionManager" /> </SPAN>  
      
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"></bean>  
      
      
    <bean id="propertyConfigurer"  
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
          <property name="location">  
             <value>/WEB-INF/systeminfo.properties</value>  
          </property>  
    </bean>  
      
    <!-- DBCP數據庫鏈接數據源的配置 -->  
      
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  destroy-method="close"> <!-- 把鏈接從新放到鏈接池裏 -->  
        <!-- 添加鏈接池屬性 -->  
        <property name="driverClassName" value="${DB.driverClassName}"/>  
        <property name="url"  value="${DB.server}"/>  
        <property name="username" value="${DB.username}"/>  
        <property name="password" value="${DB.password}"/>  
        <property name="initialSize" value="2" /> <!-- 初始鏈接數 -->  
        <property name="maxActive" value="50"/> <!-- 鏈接池最大鏈接數 -->  
        <property name="maxIdle" value="20"/>   <!-- 最大的可空閒的鏈接數 -->  
        <property name="minIdle" value="10"/>    <!-- 最小的可空閒的鏈接數 -->  
        <property name="logAbandoned" value="true" />  <!-- 超時後打印超時鏈接錯誤 -->  
        <property name="removeAbandoned" value="true" />   <!-- 超時移除鏈接 -->  
        <property name="removeAbandonedTimeout" value="300"/> <!-- 超時時間 -->  
        <property name="maxWait" value="1000"/>   <!-- 最大能夠等待時間 -->  
        <property name="defaultAutoCommit" value="true"/>  <!-- 自動提交, -->  
    </bean>  
      
    <!-- 將dataSource注入到下面的sessionFactory類裏 -->  
    <bean id="sessionFactory"  
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
        <property name="dataSource" ref="dataSource"/>  
        <property name="mappingResources">  
            <list>  
                <value>xx/bean/UserInfo.hbm.xml</value>  
                <value>xx/bean/Role.hbm.xml</value>  
            </list>  
        </property>  
        <!--  
            通配符加載方式,暫未啓用 <property name="mappingLocations"> <list>  
            <value>classpath:/jy/bean/*.hbm.xml</value> </list> </property>  
        -->  
        <property name="hibernateProperties"> <!-- 這裏是Properties列表 -->  
            <props>  
                <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect  </prop>  
                <prop key="hibernate.show_sql">true</prop> <!-- 顯示sql -->  
            </props>  
  
        </property>  
    </bean>  
    <bean id="transactionManager"  
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory" />  
    </bean>  
      
</beans>
相關文章
相關標籤/搜索