Spring配置总结 (摘)

web.xml

载入Log4j配置
<context-param><!--Log4j配置 在同一容器中部署多个应用不能使用默认的webAppRootKey,必须指定唯一KEY,以免冲突-->

    
<param-name>webAppRootKey</param-name>
    
<param-value>itservice.root</param-value>
    
<!--在log4j.properties中设置日志路径log4j.appender.file.File=${itservice.root}/WEB-INF/itservice.log-->
</context-param>
<context-param>
    
<param-name>log4jConfigLocation</param-name>
    
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
    
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

载入Spring配置文件
<context-param>
    
<param-name>contextConfigLocation</param-name>
    
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
    
<!--可载入多个配置文件分隔符-->
  
</context-param>
  
<listener>
    
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  
</listener>

字符编码过滤器
<filter>
    
<filter-name>encodingFilter</filter-name>
    
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    
<init-param>
      
<param-name>encoding</param-name>
      
<param-value>UTF-8</param-value>
    
</init-param>
</filter>
<filter-mapping>
    
<filter-name>encodingFilter</filter-name>
    
<url-pattern>/*</url-pattern>
</filter-mapping>

配置延迟加载时使用OpenSessionInView
<filter>
    
<filter-name>openSessionInViewFilter</filter-name>
    
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    
<init-param>
      
<param-name>singleSession</param-name>
      
<param-value>true</param-value>
    
</init-param>
    
<init-param>
      
<param-name>sessionFactoryBeanName</param-name>
       
<!--指定对Spring配置中哪个sessionFactory使用OpenSessionInView-->
      
<param-value>sessionFactory_itdb</param-value>
    
</init-param>
</filter>
<filter-mapping>
    
<filter-name>openSessionInViewFilter</filter-name>
    
<url-pattern>/*</url-pattern>
</filter-mapping>

 Struts-config.xml

<action input="/index.jsp"  
        name
="loginActionForm"
 
        parameter
="method"
 
        path
="/loginAction"
 
        scope
="session"
 
        type
="org.springframework.web.struts.DelegatingActionProxy"
 
        validate
="true" />

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
     
<!--将spring配置中关于ACTION的配置独立到一个action-servlet.xml文件中-->
      
<set-property property="contextConfigLocation" value="/WEB-INF/classes/action-servlet.xml" />
</plug-in>
 

applicationContext.xml

<!--直接使用hibernate配置文件-->
<bean id="sessionFactory_itdb" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    
<property name="configLocation">
         
<value>classpath:hibernate_itdb.cfg.xml</value>
    
</property>
</bean>

<!--使用JNDI DataSource-->
<bean id="it_dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    
<property name="jndiName">
        
<value>jdbc/itdb</value>
    
</property>
</bean>

<!-- Spring配置DataSource -->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    
<property name="location">
       
<value>classpath:init.properties</value>
    
</property>
  
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    
<property name="driverClassName" value="${dataSource.driverClassName}"></property>
    
<property name="url" value="${dataSource.url}"></property>
    
<property name="username" value="${dataSource.username}"></property>
    
<property name="password" value="${dataSource.password}"></property>
</bean>

<!-- *********************Hibernate*********************** -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    
<property name="dataSource" ref="dataSource"></property>
    
<property name="mappingResources">
        
<list>
            
<value>com/usish/shweb/hbm/ShwebFile.hbm.xml</value>
            
<value>com/usish/shweb/hbm/ShwebLog.hbm.xml</value>
        
</list>
    
</property>
    
<property name="hibernateProperties">
        
<props>
            
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
            
<prop key="hibernate.show_sql">false</prop>
            
<prop key="hibernate.jdbc.fetch_size">50</prop>
            
<prop key="hibernate.jdbc.batch_size">30</prop>
            
<prop key="hibernate.cache.use_second_level_cache">true</prop>
            
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
            
<prop key="hibernate.cache.use_query_cache">true</prop>
        
</props>
    
</property>
</bean>

<!--******************TransactionManager***********************-->
<bean id="transactionManager"
      class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
        
<property name="sessionFactory">
            
<ref local="sessionFactory"/>
        
</property>
</bean>
<bean id="baseTxProxy" 
      class
="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
 
      lazy-init
="true"
 
      abstract
="true">

    
<property name="transactionManager">
        
<ref bean="transactionManager" />
    
</property>
    
<property name="transactionAttributes">
        
<props>
            
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
            
<prop key="get*">PROPAGATION_REQUIRED</prop>
            
<prop key="save*">PROPAGATION_REQUIRED</prop>
            
<prop key="insert*">PROPAGATION_REQUIRED</prop>
            
<prop key="update*">PROPAGATION_REQUIRED</prop>
            
<prop key="delete*">PROPAGATION_REQUIRED</prop>
        
</props>
  
</property>
</bean> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值