当前位置: 首页 > 编程日记 > 正文

springmvc3.2+spring+hibernate4全注解方式整合(一)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"><display-name>json_test</display-name><welcome-file-list><welcome-file>login.jsp</welcome-file></welcome-file-list><!-- 加载所有的配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:com/config/spring/spring-*.xml</param-value></context-param><!-- 配置Spring监听 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 配置SpringMVC --><servlet><servlet-name>springMvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/SrpingMvc_servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springMvc</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><!-- 配置字符集 --><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- 配置Session --><filter><filter-name>openSession</filter-name><filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>openSession</filter-name><url-pattern>/*</url-pattern></filter-mapping>
</web-app>

首先从我的web.xml文件大概能看出主要配置文件的存放路径和hibernate的版本。

2、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: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.0.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd    http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"><!-- 注解探测器 --><context:annotation-config /><!-- 添加注解驱动 -->  <mvc:annotation-driven /><!-- 启动扫描所有的controller 只扫描mvc,不扫描service --><context:component-scan base-package="com.fangjian.core.web"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan> <!-- 允许对静态资源文件的访问 -->   <mvc:default-servlet-handler /> <mvc:resources mapping="/skin/**" location="/skin/" />  <!-- 定义跳转的文件的前后缀 -->  <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>  <property name="prefix" value="/WEB-INF/jsp/" />  <property name="suffix" value=".jsp" />  </bean><!-- 上传文件大小限制为31M,31*1024*1024 --><bean id="maxUploadSize" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  <property name="maxUploadSize" value="32505856" />  <property name="maxInMemorySize" value="4096" />  </bean> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 annotation默认的办法映射适配器 -->     <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />     <bean id="handlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8" /><!-- 避免IE在ajax请求时,返回json出现下载 --><bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">    <property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value></list></property></bean>
</beans>

3、spring-jdbc.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: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-3.0.xsd  http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd  http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"><!-- 引入属性文件 -->  <context:property-placeholder location="classpath:jdbc.properties" /><!-- Hibernate配置 -->    <!-- 数据源配置,使用应用内的DBCP数据库连接池 --><bean class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" id="dataSource">         <property name="driverClass" value="${jdbc.driver}">  </property>        <property name="jdbcUrl" value="${jdbc.url}">  </property>        <property name="user" value="${jdbc.username}">    </property>      <property name="password" value="${jdbc.password}">    </property>      <property name="autoCommitOnClose" value="true"> </property>         <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"> </property>         <property name="initialPoolSize" value="${cpool.minPoolSize}"> </property>         <property name="minPoolSize" value="${cpool.minPoolSize}"> </property>         <property name="maxPoolSize" value="${cpool.maxPoolSize}"> </property>         <property name="maxIdleTime" value="${cpool.maxIdleTime}"> </property>         <property name="acquireIncrement" value="${cpool.acquireIncrement}"> </property>         <property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"> </property>   </bean> <bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" id="sessionFactory">         <property name="dataSource" ref="dataSource"></property>         <property name="packagesToScan" value="com.fangjian.core.platform.po"> </property>         <property name="hibernateProperties">             <props>                 <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><prop key="javax.persistence.validation.mode">none</prop><!-- <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProviderr</prop>                 <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>                                 <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop>  -->               <prop key="current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>                  <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>         <!-- <prop key="hibernate.cache.use_second_level_cache">true</prop> -->        <prop key="hibernate.cache.use_query_cache">false</prop>          <prop key="jdbc.use_scrollable_resultset">false</prop>        <!-- <prop key="hibernate.transaction.auto_close_session">false</prop> -->            </props>        </property></bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >  <property name="dataSource" ref="dataSource"></property></bean> <!-- 事务管理器 --><bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory"><ref local="sessionFactory"/></property></bean><!-- 采用声明式容器管理事务一般只对service层进行处理 -->   <aop:config expose-proxy="true"><!-- 只对业务逻辑层实施事务 -->   <aop:pointcut id="txPointcut" expression="execution(* com.fangjian.core.platform.service.*.*(..))" /><aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>  <!-- proxy-target-class="true"<aop:advisor pointcut="execution(* com.fangjian.core.platform.service.*.*(..))" advice-ref="txAdvice"/><aop:advisor pointcut="execution(* com.fangjian.core.platform.service.*.*(..))" advice-ref="txAdvice"/>--></aop:config><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="add*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="create*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="merge*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="del*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="remove*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  <tx:method name="put*" propagation="REQUIRED" />  <tx:method name="use*" propagation="REQUIRED"/>  <!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到-->  <tx:method name="get*" propagation="REQUIRED" read-only="true" />  <tx:method name="count*" propagation="REQUIRED" read-only="true" />  <tx:method name="find*" propagation="REQUIRED" read-only="true" />  <tx:method name="list*" propagation="REQUIRED" read-only="true" />  <tx:method name="*" propagation="REQUIRED" read-only="true" rollback-for="java.lang.Exception"/>  </tx:attributes></tx:advice></beans>

4、spring自己的配置文件spring-common.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:context="http://www.springframework.org/schema/context"  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.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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"> <!-- 自动扫描组件,这里要把controler下面的 controller去除,他们是在springMvc-servlet.xml中配置的,如果不去除会影响事务管理的。   --> <context:component-scan base-package="com.fangjian.core"><context:include-filter type="annotation" expression="org.springframework.stereotype.Service" /><context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" /></context:component-scan></beans>

转载于:https://www.cnblogs.com/fangj/p/3820228.html

相关文章:

c 应用程序多语言版本,c – 在win32 API应用程序中实现全球化/多语言功能

Windows上多语言应用程序的基础是使用“资源”.资源是附加在可执行文件末尾的块,它只包含数据,并以非常特定的方式格式化,以便Windows能够解释这些数据.在资源中,您可以找到对话框,字符串表以及版本信息(在资源管理器中文件的属性对话框中显示的信息).您可以通过在Visual C中打…

整数展示分数和整形数的四则运算

文章结束给大家来个序程员笑话&#xff1a;[M] /* * Copyright (c) 2013, 烟台大学计算机学院 * All rights reserved. * 文件名称&#xff1a;test.cpp * 作者&#xff1a;邱学伟 * 成完日期&#xff1a;2013 年 5 月 4 日 * 版本号&#xff1a;v1.0 * 输入描述&#xff1a;无…

二叉树:二叉搜索树实现 逆序数问题

关于逆序数的问题描述如下&#xff1a; 已知数组nums&#xff0c;求新数组count&#xff0c;count[i]代表了在nums[i]右侧且比 nums[i]小的元素个数。 例如: nums [5, 2, 6, 1], count [2, 1, 1, 0]; nums [6, 6, 6, 1, 1, 1], count [3, 3, 3, 0, 0, 0]; nums [5, -7, 9…

C语言文件实验要求,实验教学的目的和要求.doc

实验教学的目的和要求实验教学的目的和要求&#xff1a;通过实验&#xff0c;让学生全面掌握高级语言程序设计的思想与方法&#xff0c;掌握C语言的特点&#xff0c;C语言的语法规则&#xff0c;C语言的数据类型、表达式及控制流程&#xff1b;通过编程&#xff0c;提高程序设计…

这些工作的日子

已经毕业10个月了&#xff0c;工作了9个月&#xff0c;想说我是个刚毕业的大学僧&#xff0c;没有遇到什么社会上的勾心斗角&#xff0c;没有遇到天大的难题&#xff0c;没有看到那种大起大落的景象&#xff0c;一切还是那样平平淡淡的&#xff0c;当看见附近大学的大学僧的时候…

python基础类型

range&#xff1a;生成指定范围内的数字&#xff0c;只在python2中使用&#xff0c;python3中没有此用法 例&#xff1a;生成0-30内的偶数 转载于:https://www.cnblogs.com/gaoyuxia/p/10239421.html

linux系统目录树/内核源码目录树

关于系统目录树和源码目录树的结构图如下 内核版本: centos 7.0 升级内核之后 3.10.0-957-5.1.e17

顺时针打印二维数组C语言递归,按顺时针打印矩阵

存在二种解题思路: 一种是递归解法,一种是层层递进解法图解递归解法如图所示, 一个5*5的矩阵先打印最外层的圈, 然后剩余最里层3*3的矩阵, 如图.将3*3的矩阵继续打印最外层,思路与打印最外层思路一样,我们就可以考虑使用递归实现.最后只剩余一个元素,也可以看成一个矩阵,不过不…

降低噪声和电磁干扰的原则

1.尽量采用45折线转载于:https://www.cnblogs.com/asulove/p/3827246.html

翻译:java.util.regex.Pattern

java.util.regex.PatternA compiled representation of a regular expression. A regular expression&#xff08;正则表达式&#xff09;, specified as a string, must first be compiled into an instance of this class&#xff08;首先编译成Pattern对象&#xff09;. The…

学习笔记53—Wilcoxon检验和Mann-whitney检验的区别

Wilcoxon signed-rank test应用于两个related samples Mann–Whitney U test也叫Wilcoxon rank-sum test&#xff0c;应用于两个independent samples的情samples size小的时候&#xff0c;是有列表的&#xff0c;sample size大到20左右时&#xff0c;就可以使用正态分布来近似…

s-systemtap工具使用图谱(持续更新)

整体的学习思维导图如下&#xff0c;后续持续更新完善 文章目录安装简介执行流程执行方式stap脚本语法探针语法API函数探针举例变量使用基本应用1. 定位函数位置2. 查看文件能够添加探针的位置3. 打印函数参数&#xff08;结构体&#xff09;4. 打印函数局部变量5. 修改函数局…

2014 Super Training #8 C An Easy Game --DP

原题&#xff1a;ZOJ 3791 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode3791 题意&#xff1a;给定两个0-1序列s1, s2&#xff0c;操作t次&#xff0c;每次改变m个位置&#xff0c;求把s1改变为s2的方法总数。解法&#xff1a; DP&#xff0c;s1和s2哪些位置…

qq分享组件 android,移动端,分享插件

移动端&#xff0c;分享插件发布时间&#xff1a;2018-06-26 10:03,浏览次数&#xff1a;762最近有一个活动页需要在移动端浏览器分享网页到微信&#xff0c;QQ。虽然每一个浏览器都有分享到微信的能力&#xff0c;但不是每个都提供接口供网页来调用。及时有提供&#xff0c;浏…

MySQL中更改表操作

2019独角兽企业重金招聘Python工程师标准>>> 添加一列&#xff1a; alter table t_stu add tel char(20); 删除一个列&#xff1a; alter table t_stu drop column tel; 添加唯一约束&#xff1a; alter table t_stu add constraint uk_srname unique(scode); 添加主…

Maven-环境配置

二更 可算搞好了&#xff0c;除了下面外&#xff0c;我找到了setting.xml里面的东西&#xff0c;给出来就好了&#xff0c;简单就是mvn -v弄好后&#xff0c;setting.xml里面写好的话&#xff0c;直接加入&#xff0c;然后让eclipse下载jar包 然后就可以运行网上的基本项目了 1…

分布式存储(ceph)技能图谱(持续更新)

一下为个人结合其他人对分布式存储 所需的技能进行总结&#xff0c;绘制成如下图谱&#xff0c;方便针对性学习。 这里对分布式存储系统接触较多的是ceph,所以在分布式存储系统分支上偏向ceph的学习。 如有分类有问题或者分支不合理&#xff0c;欢迎大家批评指正&#xff0c;目…

android如何查看方法属于哪个类,Android Studio查看类中所有方法和属性

css-关于位置当你设置一个你想要相对的模块为relative 你这个模块为absolute 则你的这个absolute会相对relative的那个模块进行移动.微信公众平台自动回复wechatlib&period;jar的生成及wechatlib解析微信公众平台出来有一段时日了,官方提供的自动回复的接口调用大致是这么些…

读javascript高级程序设计03-函数表达式、闭包、私有变量

一、函数声明和函数表达式 定义函数有两种方式&#xff1a;函数声明和函数表达式。它们之间一个重要的区别是函数提升。 1.函数声明会进行函数提升&#xff0c;所以函数调用在函数声明之前也不会报错&#xff1a; test(); function test(){ alert(1); } 2.函数表达式不会进行函…

集成公司内部的多个子系统(兼容B/S和C/S),实现单点登录功能的多系统的统一入口功能...

有一句话也挺有意思的&#xff0c;一直在模仿但从未超越过&#xff0c;文章里的技术也都是相对简单的技术&#xff0c;但是实实在在能解决问题&#xff0c;提高效率。现在人都懒得瞎折腾&#xff0c;能多简单就多简单&#xff0c;谁都不希望总是做一些重复的工作&#xff0c;我…

mysql无法远程连接

在mysql的mysql数据库下&#xff1a; select user,host from user;(查看&#xff0c;没有本机的访问权限) grant all privileges on *.* to root"xxx.xxx.xxx.xxx" identified by "密码";(xx为本机ip,%为所有IP) flush privileges; select user,host from …

哈希表的分类,创建,查找 以及相关问题解决

总体的hash学习导图如下&#xff1a; 文章目录定义分类字符hash排序hash链式hash&#xff08;解决hash冲突&#xff09;创建链式hash查找指定数值STL map(hash)哈希分类 完整测试代码应用&#xff08;常见题目&#xff09;1. 回文字符串&#xff08;Longest Palindrome&#x…

android 自定义音乐圆形进度条,Android自定义View实现音频播放圆形进度条

本篇文章介绍自定义View配合属性动画来实现如下的效果实现思路如下&#xff1a;根据播放按钮的图片大小计算出圆形进度条的大小根据音频的时间长度计算出圆形进度条绘制的弧度通过Handler刷新界面来更新圆形进度条的进度具体实现过程分析&#xff1a;首先来看看自定义View中定义…

jsp error-page没有生效

1、首页检查web.xml中的配置&#xff0c;确保路径是正确的 <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> 2、然后再检查error.jsp文件内容是否有问题&#xff0c;比如只有<head>&…

CTO(首席技术官)

CTO&#xff08;首席技术官&#xff09;英文Chief Technology Officer&#xff0c;即企业内负责技术的最高负责人。这个名称在1980年代从美国开始时兴。起于做很多研究的大公司&#xff0c;如General Electric&#xff0c;AT&T&#xff0c;ALCOA&#xff0c;主要责任是将科…

把数组排成最小的数

题目 输入一个正整数数组&#xff0c;把数组里所有数字拼接起来排成一个数&#xff0c;打印能拼接出的所有数字中最小的一个。例如输入数组{3&#xff0c;32&#xff0c;321}&#xff0c;则打印出这三个数字能排成的最小数字为321323。 思路 一  需要找到字典序最小的哪个排列…

shell脚本自动执行,top命令无输出

shell脚本在系统启动时推后台自动执行&#xff0c;发现其中/usr/bin/top -n 1 -c -b -u ceph 命令并无输出 但是系统启动之后手动执行脚本&#xff0c;&推后台脚本中的top仍然能够正常输出&#xff0c;仅仅是系统发生重启&#xff0c;该功能就不生效了 stackoverflow 推荐…

0709 C语言常见误区----------函数指针问题

1.函数指针的定义 对于函数 void test(int a, int b){ // } 其函数指针类型是void (* ) (int , int)&#xff0c; 注意这里第一个括号不能少&#xff0c; 定义一个函数指针&#xff0c;void (* pfunc)(int , int) ,其中pfunc就是函数指针类型&#xff0c; 它指向的函数类型必须…

android 定时换图片,android 视频和图片切换并进行自动轮播

刚入android没多久&#xff0c;遇到的比较郁闷的问题就是子线程主线程的问题&#xff0c;更改UI界面&#xff0c;本想做一个图片的轮播但是比较简单&#xff0c;然后就试试实现视频跟图片切换播放进行不停的循环播放。也用过不少控件&#xff0c;但是知其然不知其所以然&#x…

Win8:Snap 实现

Win8允许分屏的操作&#xff0c;所以我们必须让我们App能对Snap模式视图做出反应&#xff0c;这样也便于通过Store的审核。如果项目中在Snap展现的功能不大&#xff0c;我们可以仅用一张logo代替&#xff0c;类似系统的商店应用。 我的项目实现效果&#xff1a; 实现思路是在你…