您的位置:首页 > 其它

SSH三大框架整合使用的配置文件 注解实现

2014-08-11 15:59 656 查看
1 Struts。xml 使用拦截器

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">

<struts>
<include file="struts-user.xml"/>
<include file="struts-order.xml"/>
<include file="struts-cart.xml"/>
<include file="struts-main.xml"/>
<package name="dang-Default" extends="json-default">
<!-- <interceptors>
<interceptor name="transaction"
class="com.tarena.dang.interceptor.TransactionInterceptor"/>
<interceptor-stack name="dangStack">
<interceptor-ref name="transaction"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
所有Action请求使用dangStack拦截器
<default-interceptor-ref name="dangStack"/>
指定默认响应的Action
<default-action-ref name="index"/>

定义共通的拦截器,Result和Action组件
<global-results>
<result name="error">
/error.jsp
</result>
</global-results>

<global-exception-mappings>
<exception-mapping
exception="java.lang.Exception"
result="error"/>
</global-exception-mappings> -->

<!-- 处理默认响应的Action,
以redirect方式调用/mian空间下
的index请求的Action -->
<action name="index">
<result type="redirectAction">
<param name="namespace">/main</param>
<param name="actionName">index</param>
</result>
</action>

</package>

</struts>

2.Spring 的配置文件

<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 指定properties文件,后面使用${}获取 -->
<context:property-placeholder location="classpath:db.properties" />

<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="${url}">
</property>
<property name="driverClassName" value="${driverClassName}">
</property>
<property name="username" value="${username}">
</property>
<property name="password" value="${password}">
</property>
<property name="initialSize" value="${initialSize}">
</property>
<property name="maxActive" value="${maxActive}">
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource">
</property>
<property name="hibernateProperties">
<props>
<prop key="dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- 如果在Dao中使用private SessionFactory sessionFactory;
private Session getSession(){
return sessionFactory.openSession();
}
必须加入该语句 -->
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
<!-- <property name="current_session_context_class">thread</property> -->

<!-- 出现问题

   <property name="mappingResources"
value="classpath:com/tarena/dang/pojo/*.hbm.xml">
</property>
-->
<property name="mappingResources">
<list>
<value>com/tarena/dang/pojo/DBook.hbm.xml</value>
<value>com/tarena/dang/pojo/DCategory.hbm.xml</value>
<value>com/tarena/dang/pojo/DCategoryProduct.hbm.xml</value>
<value>com/tarena/dang/pojo/DComment.hbm.xml</value>
<value>com/tarena/dang/pojo/DCommentReply.hbm.xml</value>
<value>com/tarena/dang/pojo/DItem.hbm.xml</value>
<value>com/tarena/dang/pojo/DOrder.hbm.xml</value>
<value>com/tarena/dang/pojo/DProduct.hbm.xml</value>
<value>com/tarena/dang/pojo/DSendWay.hbm.xml</value>
<value>com/tarena/dang/pojo/DUser.hbm.xml</value>
</list>
</property>
</bean>

<context:component-scan base-package="com.tarena.dang"></context:component-scan>

</beans>

3. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2filter</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>

<welcome-file-list>
<welcome-file>/user/userForm.jsp</welcome-file>
</welcome-file-list>
</web-app>

有些问题的解释:http://hengstart.iteye.com/blog/858081
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐