<?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

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

  1. java spring mvc_java spring mvc 全注解

    本人苦逼学生一枚,马上就要毕业,面临找工作,实在是不想离开学校.在老师的教导下学习了spring mvc ,配置文件实在繁琐,因此网上百度学习了spring mvc 全注解方式完成spring的装配工 ...

  2. spring AOP自定义注解方式实现日志管理

    转:spring AOP自定义注解方式实现日志管理 今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接 ...

  3. Spring的AOP-AspectJ注解方式

    目录 Spring的AOP-AspectJ注解方式 1.创建类,在类里面定义方法 2.创建增强类 3.进行通知的配置 (1)在Spring 配置文件中,开启直接扫描 (2)使用注解创建User 和 U ...

  4. spring注解方式整合Dubbo源码解析

    系列文章目录 前言 本节我们的Dubbo源码版本基于2.6.x 在前一章我们的整合案例中,我们有几个比较关键的步骤: 在启动类上标注了@EnableDubbo注解 在provider类上面标注了@Se ...

  5. Spring MVC 全注解配置 (十一)

    完整的项目案例: springmvc.zip 目录 实例 项目结构: 父级的pom配置: <?xml version="1.0" encoding="UTF-8&q ...

  6. Spring Boot基于注解方式处理接口数据脱敏

    1.定义注解 创建Spring Boot项目添加以下依赖 <dependencies><dependency><groupId>org.springframewor ...

  7. spring学习--基于注解方式创建对象AOP

    概念 下面四个注解功能是一样的,都可以用来创建 bean 实例 ​ (1)@Component ​ (2)@Service ​ (3)@Controller ​ (4)@Repository 1.引入 ...

  8. 使用Spring AOP自定义注解方式实现用户操作日志记录

    1,开发环境 操作系统:Windows 7 JDK:1.8.0_161 Eclipse:Mars.2 Release (4.5.2) 2,自定义注解类UserLog @Target({ElementT ...

  9. Spring中使用XML方式导入Spring配置文件,Boot中使用全注解导入Spring配置

    目录 Spring中的方法 Spring Boot中的方法 Spring中的方法 @ImportResource:导入Spring的配置文件,让配置文件里面的内容生效: Spring Boot里面没有 ...

最新文章

  1. 记一次Debian11安装
  2. 数据库视频(二)——增删改查
  3. 投资学习网课笔记(part3)--基金第三课
  4. 02-继承的本质-Objective-C基础
  5. 人工智能第二课:认知服务和机器人框架探秘
  6. 使用方法 yii_如何实现高速卷积?深度学习库使用了这些黑魔法
  7. python辗转相除法求最小公倍数_Python实现利用最大公约数求三个正整数的最小公倍数示例...
  8. linux的一些软件的安装路径
  9. 重置winsock目录
  10. 【MyBatis】MyBatis找不到mapper文件
  11. 如何使用API爬取数据,它和网页爬虫有什么区别?
  12. 贴片电容封装及尺寸示意图
  13. 计算机报名照片在线修图,网上报名照片处理工具
  14. SWFUpload文件上传
  15. 生态 | 国内数据库领域权威学术会议NDBC 2020成功举办,人大金仓受邀参会并发表主题演讲...
  16. App中WebView网页加载优化实战干货
  17. vb.net LPT端口 开钱箱和小票纸打印超时问题解决办法
  18. 工具学习——有哪些好用的语音转文字app
  19. 简单的技能Buff系统
  20. 蚂蚁算法python_Python编程实现蚁群算法详解

热门文章

  1. 系统架构升级要不要上微服务?历“久”弥新微服务——你真的需要升级微服务架构吗
  2. 2022-2028年中国PGA树脂行业全景调研及投资前景展望报
  3. Aho-Corasick 多模式匹配算法(AC自动机) 的算法详解及具体实现
  4. 【Sql Server】数据库的3大服务
  5. Hopfiled 神经网络实例解释
  6. 机器学习数据不平衡不均衡处理之SMOTE算法实现
  7. [转载]Tensorflow 的reduce_sum()函数的axis,keep_dim这些参数到底是什么意思?
  8. CUDA 8的混合精度编程
  9. 使用多个推理芯片需要仔细规划
  10. CentOS7 php7.0 升级到php7.3