SSH配置注意事项

一:首先是wen.xml的配置是最需注意的。(顺序不能变)
1.配置sping配置文件的路径
 
<context-param>   
        <param-name>contextConfigLocation</param-name>   
        <param-value>classpath:applicationContext.xml</param-value>   
    </context-param> 

2.配置事件监听
  
 <listener>  
        <listener-class>  
            org.springframework.web.context.ContextLoaderListener  
        </listener-class>  
    </listener> 

3.配置过滤器
  
 <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


二.在省去hibernate配置文件的情况下,配置application.xml
   1.数据源
  
<bean id="dataSource"    
        class="org.apache.commons.dbcp.BasicDataSource">    
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/test"></property>
          
        <property name="username" value="root"></property> 
        <property name="password" value="788124"></property> 
    </bean>   

   2.session工厂
   
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
        <property name="dataSource">  
            <ref bean="dataSource"/>  
        </property>     
        <property name="hibernateProperties">    
            <props>    
                <prop key="hibernate.dialect">
                   org.hibernate.dialect.MySQLDialect
                </prop>    
            </props>    
        </property>    
        <property name="mappingResources">    
            <list>    
                <value>springModel/Person.hbm.xml</value>
            </list>    
        </property> 
    </bean>  

3.配置事物管理
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
       <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 

	<tx:advice id="txAdvice" transaction-manager="transactionManager"> 
	  <tx:attributes> 
	   <tx:method name="add*" propagation="REQUIRED"/> 
	   <tx:method name="del*" propagation="REQUIRED"/> 
	   <tx:method name="update*" propagation="REQUIRED"/> 
	   <tx:method name="get*" propagation="SUPPORTS" read-only="true"/> 
	   <tx:method name="search*" propagation="SUPPORTS" read-only="true"/> 
	  </tx:attributes> 
	</tx:advice>
	<aop:config> 
	<aop:pointcut id="affectMethods" expression="execution(* edu.accp.dao.hibImpl.*.*(..))"/> 
	  <aop:advisor advice-ref="txAdvice" pointcut-ref="affectMethods"/> 
	</aop:config> 

源代码如下:
  

你可能感兴趣的:(java,Hibernate,xml,ssh,配置管理)