整合ssh框架的配置文件
2016-11-04 21:47
357 查看
ssh整合
一.applicationContext.xml
1配置数据源
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties"></property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
2.配置hibernate的sessionFactory工厂
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>//引用数据源
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>//配置相关数据库库的方言(为了检查hql翻译sql语句的语法)
<prop key="hibernate.show_sql">false</prop>//是否显示sql语句
<prop key="hibernate.format_sql">false</prop>//格式化sql语句
</props>
</property>
<!-- 直接配置注解的实体类(不用再编写配置xxx.hbm.xml文件)-->
<property name="annotatedClasses">
<list>
<value>cn.sxt.vo.ceshi.Module</value>
<value>cn.sxt.vo.ceshi.Suite</value>
</list>
</property>
</bean>
3.配置事务管理器(此管理器是hibernate提供的,其实spring也有事务管理器)
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
4.配置事务监听器
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>//监听所有的方法
</tx:attributes>
</tx:advice>
5.配置事务提交的切入点
<aop:config>
<aop:pointcut expression="execution(* cn.sxt.service..*.*(..))" id="pointcut"/>//切入点
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>//引用事务监听器
</aop:config>
6.配置注解扫描器
<context:component-scan base-package="cn.sxt"/>//扫描sxt包的所有类里面的注解
二.strut.xml
添加相应的映射文件就可以了
例如:<struts>
<package name="yxl" extends="struts-default"></package>
<include file="config/yxl/struts/ceshi.xml"></include>
<include file="config/yxl/struts/suite.xml"></include>
<include file="config/yxl/struts/module.xml"></include>
</struts>
三.web.xml
1.配置spring容器相关的资源文件和创建容器的监听类
<!--定位spring配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--web容器启动时就会触发此监听器调用相应的方法创建spring容器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>//
</listener>
2.配置session的关闭的一个过滤器
<filter>
<filter-name>osiv</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>osiv</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.配置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>*.action</url-pattern>
</filter-mapping>
一.applicationContext.xml
1配置数据源
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties"></property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
2.配置hibernate的sessionFactory工厂
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>//引用数据源
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>//配置相关数据库库的方言(为了检查hql翻译sql语句的语法)
<prop key="hibernate.show_sql">false</prop>//是否显示sql语句
<prop key="hibernate.format_sql">false</prop>//格式化sql语句
</props>
</property>
<!-- 直接配置注解的实体类(不用再编写配置xxx.hbm.xml文件)-->
<property name="annotatedClasses">
<list>
<value>cn.sxt.vo.ceshi.Module</value>
<value>cn.sxt.vo.ceshi.Suite</value>
</list>
</property>
</bean>
3.配置事务管理器(此管理器是hibernate提供的,其实spring也有事务管理器)
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
4.配置事务监听器
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>//监听所有的方法
</tx:attributes>
</tx:advice>
5.配置事务提交的切入点
<aop:config>
<aop:pointcut expression="execution(* cn.sxt.service..*.*(..))" id="pointcut"/>//切入点
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>//引用事务监听器
</aop:config>
6.配置注解扫描器
<context:component-scan base-package="cn.sxt"/>//扫描sxt包的所有类里面的注解
二.strut.xml
添加相应的映射文件就可以了
例如:<struts>
<package name="yxl" extends="struts-default"></package>
<include file="config/yxl/struts/ceshi.xml"></include>
<include file="config/yxl/struts/suite.xml"></include>
<include file="config/yxl/struts/module.xml"></include>
</struts>
三.web.xml
1.配置spring容器相关的资源文件和创建容器的监听类
<!--定位spring配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--web容器启动时就会触发此监听器调用相应的方法创建spring容器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>//
</listener>
2.配置session的关闭的一个过滤器
<filter>
<filter-name>osiv</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>osiv</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.配置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>*.action</url-pattern>
</filter-mapping>
相关文章推荐
- SSH框架整合配置文件模式2
- SSH框架整合——基于XML配置文件
- ssh框架中spring整合hibernate的配置文件模板(带详细注释)
- SSH框架整合模板配置文件
- 整合SSH框架配置文件
- Java乔晓松-SSH框架整合配置文件的配置以及事务处理
- 关于SSH框架整合中,数据库配置文件加密解决思路记载
- spring_day4_09-ssh框架整合其他方式(没有hibernate核心配置文件)
- ssh框架整合配置文件
- SSH框架整合的MAVEN项目之配置文件整合
- 关于SSH框架整合中web.xml文件的配置详解
- JavaEE SSH框架整合(二) struts2 加载本地dtd文件,action配置
- SSH框架整合配置文件模式1
- SSH框架学习语录三:Struts2+Spring, 将框架的配置文件整合起来
- ssh框架整合实例子1-配置文件
- Spring+hibernate整合常用的配置文件
- struts+hibernate+spring 整合配置文件
- struts1+hibernate+spring整合配置文件写法
- jdbc和spring的整合,部分配置文件
- SSH2整合项目开发中spring配置文件applicationContext.xml分析