您的位置:首页 > 编程语言 > Java开发

Spring+Hibernate+WebWork配置

2009-06-29 09:52 423 查看
配置文件:

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以上。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: