SSH配置文件(注解)

来源:互联网 发布:淘宝海外购 编辑:程序博客网 时间:2024/05/19 18:12

web.xml配置:

<!-- 配置环境参数,指定spring配置文件的位置 -->

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml  
   </param-value>
</context-param>
<!-- 配置spring的ContextLoaderListener监听器,初始化spring容器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>


<!-- 配置struts环境 -->
<!-- openSessionInViewFilter(必须配置在struts核心控制器之前才有效果) -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- struts核心控制器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

配置applicationContext.xml
头部文件:

<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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<!-- 扫描包中注解标注的类 -->
<context:component-scan base-package="cn.dwh.dao" />
<context:component-scan base-package="cn.dwh.service" />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver">
</property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>cn.bdqn.Entity.Goods</value>
</list>
</property>
</bean>


<!-- 声明事务 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* cn.bdqn.Service..*.*(..))"
id="pointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
</aop:config>


配置Struts2.xml

<struts>
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.i18n.encoding" value="utf-8" />
<package name="default" extends="struts-default,json-default">
<action name="Login" class="org.action.LoginAction" method="Login">
<result>index.jsp</result>
<result name="input">login.jsp</result>
</action>
<action name="datagrid" class="org.action.SubjectAction"
method="backList">
<result type="json">
<param name="root">map</param>
</result>
</action>
</package>
</struts>



1 0
原创粉丝点击