spring +spring+ hibernate配置1
这种配置方式是将Spring 、SpringMVC、Hibernate三个模块分开配置,交叉引用!hibernate连接配置使用.properties文件
web.xml配置
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
<display-name>Archetype Created Web Application</display-name> <!-- Spring MVC servlet -->
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list> </web-app>
spring.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- 引入属性文件 -->
<context:property-placeholder location="classpath:config.properties" />
<import resource="classpath:spring-hibernate.xml"/> <!-- 自动扫描 -->
<context:component-scan base-package="com.service" /> </beans>
SpringMVC.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <mvc:annotation-driven/>
<mvc:default-servlet-handler/> <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
<context:component-scan base-package="com.controller" /> <!-- 定义跳转的文件的前后缀 ,视图模式配置-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean> </beans>
spring_hibernate.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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- JNDI(通过Tomcat)方式配置数据源 -->
<!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jndiName}"></property> </bean> --> <!-- 配置数据源 -->
<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_username}" />
<property name="password" value="${jdbc_password}" /> <!-- 初始化连接大小 -->
<property name="initialSize" value="0" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="20" />
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="20" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="0" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="60000" /> <!-- <property name="poolPreparedStatements" value="true" /> <property
name="maxPoolPreparedStatementPerConnectionSize" value="33" /> --> <property name="validationQuery" value="${validationQuery}" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="25200000" /> <!-- 打开removeAbandoned功能 -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" /> <!-- 监控数据库 -->
<!-- <property name="filters" value="stat" /> -->
<property name="filters" value="mergeStat" /> </bean> <!-- 配置hibernate session工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property> <!-- 自动扫描注解方式配置的hibernate类文件 -->
<property name="packagesToScan">
<list>
<value>com.dao</value>
</list>
</property>
</bean> <!-- 配置事务管理器 -->
<bean name="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 注解方式配置事物 -->
<tx:annotation-driven transaction-manager="transactionManager" /> <!-- 拦截器方式配置事物 -->
<!-- <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes> <tx:method name="add*" /> <tx:method name="save*" /> <tx:method
name="update*" /> <tx:method name="modify*" /> <tx:method name="edit*" />
<tx:method name="delete*" /> <tx:method name="remove*" /> <tx:method name="repair"
/> <tx:method name="deleteAndRepair" /> <tx:method name="get*" propagation="SUPPORTS"
/> <tx:method name="find*" propagation="SUPPORTS" /> <tx:method name="load*"
propagation="SUPPORTS" /> <tx:method name="search*" propagation="SUPPORTS"
/> <tx:method name="datagrid*" propagation="SUPPORTS" /> <tx:method name="*"
propagation="SUPPORTS" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut
id="transactionPointcut" expression="execution(* com.jesus.sshframework.service..*Impl.*(..))"
/> <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice"
/> </aop:config> --> </beans>
congfig.properties (hibernate连接配置)
#MySQL
hibernate.dialect=org.hibernate.dialect.MySQLDialect
driverClassName=com.mysql.jdbc.Driver
validationQuery=SELECT 1
jdbc_url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8
jdbc_username=root
jdbc_password= hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=false sessionInfoName=sessionInfo uploadFieldName=filedata
uploadFileMaxSize=20971520
uploadFileExts=txt,rar,zip,doc,docx,xls,xlsx,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid
uploadDirectory=attached
spring +spring+ hibernate配置1的更多相关文章
- spring + springMVC +hibernate 配置2
		
这种方式比较精简 配置项不多 spring采用自动扫描配置 ,分spring_springMVC.xml . hibernate_config.xml 两个文件 web.xml配置如下 <?x ...
 - Spring+Hibernate整合配置   ---  比较完整的spring、hibernate 配置
		
Spring+Hibernate整合配置 分类: J2EE2010-11-25 17:21 16667人阅读 评论(1) 收藏 举报 springhibernateclassactionservlet ...
 - 解决在Spring整合Hibernate配置tx事务管理器出现错误的问题
		
问题描述: Error occured processing XML 'org/aopalliance/intercept/MethodInterceptor'. See Error Log for ...
 - spring,hibernate配置事务
		
1. 新建java project 2. 引入jar 3. src下新建package:com.web.model, com.web.dao, com.web.service, bean.xml 4. ...
 - SPRING+JPA+Hibernate配置方法
		
1.applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...
 - spring,hibernate配置事务 beans.xml
		
beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
 - Spring MVC+Spring +Hibernate配置事务,但是事务不起作用
		
最近做项目,被一个问题烦恼了很久.使用Spring MVC+Spring +Hibernate开发项目,在使用注解配置事务管理,刚开始发现无论如何数据库都无法更新,但是可以从数据库查询到数据.怀疑是配 ...
 - Spring+Struts2+Hibernate框架整合流程
		
一:基本步骤 新建Maven项目,导入相关依赖(推荐) 在WEB-INF的web.xml中进行配置 ————–Hibernate配置 —————- 创建entity包,创建数据库相关实体类 根据实体类 ...
 - javaweb各种框架组合案例(三):maven+spring+springMVC+hibernate
		
1.hibernate译为"越冬",指的是给java程序员带来春天,因为java程序员无需再关心各种sql了: 2.hibernate通过java类生成数据库表,通过操作对象来映射 ...
 - C3P0连接池在hibernate和spring中的配置
		
首先为什么要使用连接池及为什么要选择C3P0连接池,这里就不多说了,目前C3P0连接池还是比较方便.比较稳定的连接池,能与spring.hibernate等开源框架进行整合. 一.hibernate中 ...
 
随机推荐
- Python基础——函数入门
			
等待更新…………………… 后面再写
 - decodeURI     decodeURIComponent
			
操作 url 常用到编码与解码,一一对应就好 给力文章
 - Spring Boot任务(定时,异步,邮件)
			
一.定时任务 开启定时任务(在Spring Boot项目主程序上添加如下注解) @EnableScheduling //开启定时任务的注解 创建定时任务(创建一个Service如下) @Service ...
 - 01.LNMP架构-Nginx源码包编译部署详细步骤
			
操作系统:CentOS_Server_7.5_x64_1804.iso 部署组件:Pcre+Zlib+Openssl+Nginx 操作步骤: 一.创建目录 [root@localhost ~]# mk ...
 - apache 修改文件上传大小限制
			
Windows 环境下的修改方法 ================================================================ 第一步:修改在php5下POST文件 ...
 - ceph对接openstack
			
一.使用rbd方式提供存储如下数据: (1)image(glance):保存glanc中的image: (2)volume(cinder)存储:保存cinder的volume:保存创建虚拟机时选择创建 ...
 - Wide&Deep 模型学习教程
			
WDL 学习教程 推荐系统+WDL 教学视频: https://www.bilibili.com/video/av29905315/ WDL 模型介绍: https://blog.csdn.net/g ...
 - Python线程学习
			
Python3 通过两个标准库 _thread 和 threading 提供对线程的支持. _thread 提供了低级别的.原始的线程以及一个简单的锁,它相比于 threading 模块的功能还是比较 ...
 - golang初识 和 变量,常量,iota
			
目录 一.go语言与python 1. go语言 2. python 二.变量相关 1. go语言的基本语法 2. 标识符和关键字 3. 变量声明 (1)声明变量时未指定初始值 (2)声明变量时指定初 ...
 - 【Luogu5294】[HNOI2019]序列
			
题目链接 题意 给定一个序列,要求将它改造成一个非降序列,修改一个数的代价为其改变量的平方. 最小化总代价. 另有\(Q\) 次询问,每次修改一个位置上的数.(询问之间独立,互不影响) Sol 神仙 ...