springMVC+spring+hibernate基础配置文件
来源:互联网 发布:minecraft java 编辑:程序博客网 时间:2024/06/05 08:33
一,配置springMVC
<?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:mvc="http://www.springframework.org/schema/mvc" 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-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="cn.cque.controller" />
<!-- spring mvc不能处理的请求交给Tomcat -->
<mvc:default-servlet-handler/>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<mvc:annotation-driven/>
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp" />
</bean>
</beans>
二 。 配置spring与hibernate的整合
<?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-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<!-- 开启注解功能 -->
<context:annotation-config />
<!-- 指定jdbc配置文件的位置 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 指定扫描dao包 -->
<context:component-scan base-package="cn.cque.dao.impl" />
<!-- 是定扫描service包 -->
<context:component-scan base-package="cn.cque.service" />
<!-- 数据库连接池,配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.name}" />
<property name="password" value="${jdbc.password}" />
<property name="driverClassName" value="${jdbc.DriverClass}" />
</bean>
<!-- spring与hibernate整合配置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 扫描实体类包 -->
<property name="packagesToScan">
<list>
<value>cn.cque.entity</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="current_session_context_class">thread</prop>
<prop key="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</prop>
</props>
</property>
</bean>
<!-- hibernate事物管理 -->
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 切入规则 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<!-- add开头的方法的事物传播规则 -->
<tx:method name="add*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!-- aop配置 -->
<aop:config>
<!-- 切入点 ,所有的事物方法为事物方法-->
<aop:pointcut id="businessService"
expression="execution(public * cn.cque.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="businessService" />
</aop:config>
</beans>
- springMVC+spring+hibernate基础配置文件
- spring+springMVC+Hibernate配置文件
- spring/springmvc/spring+hibernate(mybatis)配置文件
- Spring+springmvc+hibernate+redis整合配置文件
- spring+springMVC+Hibernate全注解XML配置文件
- spring-springmvc-hibernate整合之配置文件
- springMVC+hibernate+spring干净的一个配置文件
- spring(一)--spring/springmvc/spring+hibernate(mybatis)配置文件
- SpringMVC、Spring、Hibernate整合基础配置
- Spring+SpringMVC整合----配置文件
- springmvc项目:spring配置文件
- Spring基础五之Springmvc和hibernate事务不提交
- hibernate+spring配置文件
- spring+struts+hibernate配置文件
- spring+hibernate事务管理配置文件
- spring+hibernate配置文件
- struts2+hibernate+spring配置文件
- Hibernate+struts+spring配置文件
- 牛客网---2016---美团字符串计数
- 正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
- 十步完全理解 SQL
- Pyspider实例之抓取小米众筹产品
- Spark-Streaming的window滑动窗口及热点搜索词统计案例
- springMVC+spring+hibernate基础配置文件
- SQL SERVER运维日记--收缩数据库
- Mysql
- 上传更新后的文件 use scp
- log4j2.xml
- Ubuntu 安装 Sublime Text
- jq的html()、text()、val()的使用
- 分库分表需要考虑的问题及方案
- mybatis-generator自动生成代码