Spring+Hibernate+WebWork配置

配置文件:

src目录下:

ehcache.xml

jdbc.properties

log4j.properties

webwork.properties

webwork-user.xml

xwrok.xml

 

web/WEB-INF目录下:

applicationContext.xml

jdbc.properties

web.xml

pager-taglib.tld

spring.tld

spring-form.tld

webwork.tld

 

经自动编译后自动进入web/WEB-INF/classes目录下:

ehcache.xml

jdbc.properties

webwork.properties

log4j.properties

webwork-user.xml

xwork.xml

 

配置文件基本的详细配置如下:

ehcache.xml

<ehcache>

    <!-- Sets the path to the directory where cache .data files are created.

         If the path is a Java System Property it is replaced by
         its value in the running VM.

         The following properties are translated:
         user.home - User's home directory
         user.dir - User's current working directory
         java.io.tmpdir - Default temp file path -->
    <diskStore path="java.io.tmpdir"/>

    <!--Default Cache configuration. These will applied to caches programmatically created through
        the CacheManager.

        The following attributes are required:

        maxElementsInMemory            - Sets the maximum number of objects that will be created in memory
        eternal                        - Sets whether elements are eternal. If eternal,  timeouts are ignored and the
                                         element is never expired.
        overflowToDisk                 - Sets whether elements can overflow to disk when the in-memory cache
                                         has reached the maxInMemory limit.

        The following attributes are optional:
        timeToIdleSeconds              - Sets the time to idle for an element before it expires.
                                         i.e. The maximum amount of time between accesses before an element expires
                                         Is only used if the element is not eternal.
                                         Optional attribute. A value of 0 means that an Element can idle for infinity.
                                         The default value is 0.
        timeToLiveSeconds              - Sets the time to live for an element before it expires.
                                         i.e. The maximum time between creation time and when an element expires.
                                         Is only used if the element is not eternal.
                                         Optional attribute. A value of 0 means that and Element can live for infinity.
                                         The default value is 0.
        diskPersistent                 - Whether the disk store persists between restarts of the Virtual Machine.
                                         The default value is false.
        diskExpiryThreadIntervalSeconds- The number of seconds between runs of the disk expiry thread. The default value
                                         is 120 seconds.
        -->

    <defaultCache
        maxElementsInMemory="1000"
        eternal="false"
        timeToIdleSeconds="3600"
        timeToLiveSeconds="3600"
        overflowToDisk="false"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120"
        />

    <!--Predefined caches.  Add your cache configuration settings here.
        If you do not have a configuration for your cache a WARNING will be issued when the
        CacheManager starts

        The following attributes are required:

        name                           - Sets the name of the cache. This is used to identify the cache.
                                         It must be unique.
        maxElementsInMemory            - Sets the maximum number of objects that will be created in memory
        eternal                        - Sets whether elements are eternal. If eternal,  timeouts are ignored and the
                                         element is never expired.
        overflowToDisk                 - Sets whether elements can overflow to disk when the in-memory cache
                                         has reached the maxInMemory limit.

        The following attributes are optional:
        timeToIdleSeconds              - Sets the time to idle for an element before it expires.
                                         i.e. The maximum amount of time between accesses before an element expires
                                         Is only used if the element is not eternal.
                                         Optional attribute. A value of 0 means that an Element can idle for infinity.
                                         The default value is 0.
        timeToLiveSeconds              - Sets the time to live for an element before it expires.
                                         i.e. The maximum time between creation time and when an element expires.
                                         Is only used if the element is not eternal.
                                         Optional attribute. A value of 0 means that and Element can live for infinity.
                                         The default value is 0.
        diskPersistent                 - Whether the disk store persists between restarts of the Virtual Machine.
                                         The default value is false.
        diskExpiryThreadIntervalSeconds- The number of seconds between runs of the disk expiry thread. The default value
                                         is 120 seconds.
        -->
  
</ehcache>

 

jdbc.properties

### C3P0 Connection Pool
c3p0.acquireIncrement=3
c3p0.minPoolSize=3
c3p0.maxPoolSize=10
c3p0.maxIdleTime=1800
c3p0.maxStatementsPerConnection=30
c3p0.idleConnectionTestPeriod=600

### mysql
hibernate.dialect=org.hibernate.dialect.MySQLDialect
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/myjdpm?useUnicode=true&characterEncoding=GBK
jdbc.username=root
jdbc.password=

 

log4j.properties

log4j.rootLogger = INFO,stdout

log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{ISO8601} %-5p [%F:%L] : %m%n

 

webwork.properties

# extension for actions
webwork.action.extension=action

# spring integration
webwork.objectFactory=spring
webwork.objectFactory.spring.autoWire=type

### Configuration reloading
# This will cause the configuration to reload xwork.xml when it is changed
webwork.configuration.xml.reload=true

### character encoding
webwork.locale=zh_CN
webwork.i18n.encoding=GBK

 

webwork-user.xml

<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd ">

<xwork>
    <package name="user" extends="webwork-default" namespace="/user">
        <default-interceptor-ref name="defaultStack"/>
  
 <action name="login" class="loginAction">
  <result name="success" type="dispatcher">/login/loginSuccess.jsp</result>
    </action>
  
 </package>
</xwork>

 

xwork.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd ">

<xwork>
 <include file="webwork-default.xml"/>
    <include file="webwork-user.xml" />
</xwork>

 

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd ">

<beans>
 <bean id="propertyConfigurer"
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
   <value>/WEB-INF/jdbc.properties</value>
  </property>
 </bean>

 <bean id="nativeJdbcExtractor"
  class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" >
 </bean>

 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
        <property name="minPoolSize" value="${c3p0.minPoolSize}" />
        <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
        <property name="maxIdleTime" value="${c3p0.maxIdleTime}" />
        <property name="maxStatementsPerConnection" value="${c3p0.maxStatementsPerConnection}" />
        <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" />
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
   
 <bean id="baseTransaction" abstract="true"
      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="transactionAttributes">
   <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property> 
    </bean>

 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="mappingResources">
   <list>
    <value>user/model/User.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            </props>
        </property>
  <property name="dataSource" ref="dataSource">
  </property>
 </bean>
  
    <bean id="userService" parent="baseTransaction">
        <property name="target">
            <bean class="user.service.impl.UserServiceImpl">
                <property name="sessionFactory">
                    <ref local="sessionFactory" />
                </property>
            </bean>
        </property>
        <property name="proxyInterfaces">
            <value>user.service.UserService</value>
        </property>
    </bean>
   
    <bean id="loginAction" class="user.action.UserLoginAction" singleton="false">
  <property name="userService">
   <ref local="userService" />
  </property>
 </bean>

</beans>

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
 <!-- Configuration Listener -->
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
   
    <servlet>
  <servlet-name>webwork2</servlet-name>
  <servlet-class>
   com.opensymphony.webwork.dispatcher.ServletDispatcher
  </servlet-class>
  <load-on-startup>2</load-on-startup>
 </servlet>
   
    <servlet-mapping>
        <servlet-name>webwork2</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>
</web-app>

 

注意点:

此处的webwork的配置方式需要webwork的JAR包版本在2.2以上。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值