新浪旧事-webwork、webwork+spring和webwork+spring+hibernate

webwork:

 

jar包:

commons-logging.jar
freemarker.jar
javassist.jar
ognl.jar
oscore.jar
rife-continuations.jar
webwork-2.2.7.jar
xwork.jar

 

web.xml中添加:

<filter>
    <filter-name>webwork</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>webwork</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

src/xwork.xml内容的第一行:

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

webwork+spring:

 

jar包:

commons-logging.jar
freemarker.jar
javassist.jar
ognl.jar
oscore.jar
rife-continuations.jar
webwork-2.2.7.jar
xwork.jar
org.springframework.asm.jar
org.springframework.beans.jar
org.springframework.context.jar
org.springframework.core.jar
org.springframework.expression.jar
org.springframework.web.jar

 

web.xml中添加:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 
<filter>
    <filter-name>webwork</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
 
<filter-mapping>
    <filter-name>webwork</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
 
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>

注意:context-param要灵活配置,contextConfigLocation指明了spring的配置文件的位置和文件名。

 

假设的applicationContext-bean.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="userDao" class="dao.impl.UserDaoImpl">
    </bean>
 
</beans>

假设的applicationContext-action.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="registerAction" class="action.RegisterAction">
        <property name="userDao" ref="userDao"></property>
    </bean> 
</beans>

假设的xwork.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
    <include file="webwork-default.xml" />
 
    <package name="webwork" extends="webwork-default">
        <action name="register" class="registerAction">
            <result name="success">/success.jsp</result>
        </action>
    </package>
</xwork>

千万记得,一定要有的一个文件——src/webwork.properties:

webwork.objectFactory=spring
webwork.objectFactory.spring.autoWire=true

webwork+spring+hibernate:

jar包:

commons-logging.jar
freemarker.jar
javassist.jar
ognl.jar
oscore.jar
rife-continuations.jar
webwork-2.2.7.jar
xwork.jar
org.springframework.asm.jar
org.springframework.beans.jar
org.springframework.context.jar
org.springframework.core.jar
org.springframework.expression.jar
org.springframework.web.jar
aopalliance.jar
aspectjweaver.jar
commons-collections.jar
dom4j.jar
hibernate3.jar
jta.jar
log4j.jar
mysql-connector-java.jar
org.springframework.aop.jar
org.springframework.jdbc.jar
org.springframework.orm.jar
org.springframework.transaction.jar
slf4j-api.jar
slf4j-log4j12.jar

 

web.xml在webwork+spring的基础上,再加上:

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


applicationContext-bean.xml和applicationContext-action.xml的使用方法不变,在这个基础上,加一个文件——applicationContext-common.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
    </bean>
 
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
 
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="create*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="read*" propagation="REQUIRED"/>
            <tx:method name="list*" propagation="REQUIRED"/>
            <tx:method name="*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
 
    <aop:config>
        <aop:pointcut expression="execution(* dao.*.*(..))" id="allManagerMethod"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
    </aop:config>
</beans>

其他文件,例如xwork.xml、webwork.properties等文件使用方法不变,在此基础上加上log4j.properties、hibernate.cfg.xml、User.hbm.xml等,即可使用。

你可能感兴趣的:(spring,AOP,Hibernate,Webwork,encoding,attributes)