Spring+Hibernate+WebWork配置

來源:互聯網
上載者:User

設定檔:

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以上。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.