科帮网-Java论坛、Java社区、JavaWeb毕业设计

登录/注册
您现在的位置:论坛 盖世程序员(我猜到了开头 却没有猜到结局) 项目源码 > SpringMVC+hibernate4.3+Spring4.1整合案例
总共48086条微博

动态微博

查看: 8176|回复: 10

SpringMVC+hibernate4.3+Spring4.1整合案例

[复制链接]
admin    

1244

主题

544

听众

1万

金钱

管理员

  • TA的每日心情

    2021-2-2 11:21
  • 签到天数: 36 天

    [LV.5]常住居民I

    管理员

    跳转到指定楼层
    楼主
    发表于 2015-04-15 20:59:36 |只看该作者 |倒序浏览
    springMVC+hibernate4.3+Spring4.1整合案例spring.xml:
    ! Q' b8 a! A; o. h9 ?! \' o* j9 s( q" y) t* _1 |* z/ b5 W
    1. <?xml version="1.0" encoding="UTF-8"?>  
      7 f: t- K  i( j5 f
    2. <beans xmlns="http://www.springframework.org/schema/beans"   
      8 t2 d9 v0 m+ ]9 B! ?
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
      0 \. {0 p2 t2 X/ B
    4.     xmlns:p="http://www.springframework.org/schema/p"  
      ! c: ?. v% X5 ~7 v/ W; L3 @- k" C1 J
    5.     xmlns:aop="http://www.springframework.org/schema/aop"   
      # a' B$ n* z1 {- P: `5 e# M6 y$ k
    6.     xmlns:context="http://www.springframework.org/schema/context"  " o& x8 O" q# q& {/ X
    7.     xmlns:jee="http://www.springframework.org/schema/jee"  
      / Y0 i  b  N6 l# S* ]
    8.     xmlns:tx="http://www.springframework.org/schema/tx"  3 ]4 p' e& ~. n% ?( M* n' ?- G8 A
    9.     xsi:schemaLocation="   
      ! k3 Z% c$ e, R+ H
    10.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  % ?( X: `8 a7 N5 t7 t
    11.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  . W) `7 K  g& k% k
    12.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
      2 k0 b4 F- O& N
    13.         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
      $ c) s& v9 @. m3 Y$ P# g6 W
    14.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
      3 |1 |" V# U; D( F; ~, n
    15.     ' _9 P' f, c4 m
    16.     <!-- <mvc:annotation-driven /> -->
        z* F' f% {1 j* g& w9 z
    17.     <!-- 【配置视图解析器】 -->  . h4 G' z) N" D
    18.     <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->  / L. F$ U" ?6 e7 D5 a5 H
    19.     <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 -->  " J$ W* J* q* P# A
    20. <!--    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
      9 h# Z! y, n/ W
    21.         <property name="prefix" value="/WEB-INF/jsp/"/>  . L3 v' {% ?9 U5 a$ ~) l/ |
    22.         <property name="suffix" value=".jsp"/>
      : s7 h4 }1 G" Q- R" A: _- u
    23.     </bean> -->
      $ t8 Y, g! q3 g; |  P! D: o; D
    24.    
      % Q1 e* Z- p4 b
    25.     <!--  导入springMvc.xml配置文件 -->4 t- B" K6 d7 x' P/ x
    26.     <import resource="classpath:config/spring-mvc.xml" />
      9 g" e, o6 @& S" t6 }
    27.     <!-- 加载数据库配置 -->
      2 b# l+ z8 B% y) [3 J# [
    28.     <context:property-placeholder location="classpath:config/db.properties" />
      6 p6 U$ W* y' g% G- E
    29.         <!-- 加载数据源 -->" s5 a9 R' `2 q) `: q* u6 \, W
    30.         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">1 T3 s+ y$ t5 j; V
    31.                 <property name="driverClassName" value="${db.driverClassName}" /># r9 i' j  x, _4 u' |' L
    32.                 <property name="url" value="${db.url}" />. d5 S# v. Z9 h" N
    33.                 <property name="username" value="${db.username}" />4 M+ i9 J0 g2 h
    34.                 <property name="password" value="${db.password}" />5 Q0 H& X. W1 D8 f
    35.                 <property name="maxActive" value="${db.maxActive}" />1 _3 C- v' p. F
    36.                 <property name="maxIdle" value="${db.maxIdle}" />" z6 b7 u  d7 ^/ h" F  t2 }* \5 J
    37.                 <property name="minIdle" value="${db.minIdle}" />
      5 u5 b4 r: o( Z  ~; P2 k6 t4 t
    38.                 <property name="maxWait" value="${db.maxWait}" />
      8 b6 M9 r8 {$ W8 t
    39.         </bean>  [8 ]7 {9 J, Y. \7 h7 |# y3 F6 r
    40.     * S' \0 v7 q' l5 J
    41.    
      4 g: Q0 Z0 J, {; Z- V
    42.     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  ' X' p/ ~0 @7 J! T  \+ i; i
    43.         <property name="dataSource" ref="dataSource" />  
      1 ]$ U) W. n) }1 e9 T& f
    44.         <property name="mappingDirectoryLocations">  6 i. i' ^! n2 |& Y8 b$ v/ H8 ]
    45.                   <list>
      + p$ G* _* t' j# u
    46.                                 <value>classpath:config/hbm/</value>
        c8 k3 P1 g+ C5 I4 x
    47.                         </list>. y) H0 T7 K  d
    48.         </property>  
      ( i2 p. g* s% ?/ k: \& j
    49.         <property name="hibernateProperties">    s1 P7 c8 X0 ~6 a& N
    50.             <props>
      0 g: b" Z: m3 M
    51.                                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>
      5 E& M3 `* \/ R; \4 @
    52.                                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
      & F& L6 d. v% f7 W2 P* s
    53.                                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
      0 `% B! Z/ i% N" O6 `
    54.                                 <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->
      3 k* R7 t# E! j1 _1 t
    55.                                 </props>
      6 X2 N  H0 f8 r3 O1 V/ V# w9 o, U# R
    56.         </property>  
      1 v: y: |% T& @" D' D1 e9 n
    57.     </bean>
      ' c  F" U( |3 C" a2 I/ r, j9 ?
    58.     " J( W" h- T& @% q" a4 @) a
    59.     <!-- 声明式事务 -->  / E0 z- q- c9 e9 }1 o& D
    60.     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
      / D; V) v: w  \# E* o* S
    61.         <property name="sessionFactory" ref="sessionFactory" />  
      1 K* A( h& D8 K' }6 [+ ~. ^
    62.     </bean>  " t+ s- c, K2 b* E7 B
    63.           6 J9 p: v/ f5 S3 P) _# d
    64.     <aop:config>  
      " Z' N  F) D5 {% e" ~$ u' n) b" c
    65.         <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />  # P) ^: Z) v" s
    66.         <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />  
      7 W' @6 x. \: f3 a
    67.     </aop:config>  ! T& G' B! Z% S; m. L/ g' q
    68.       
      ) ~( Z! @+ U. f$ z, j1 B
    69.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  $ f" c( k" ^+ w! j$ N) z
    70.         <tx:attributes>  : D4 C8 u1 v5 o, j
    71.                 <tx:method name="save*"   propagation="REQUIRED" />
      5 I7 m# N: o2 b! K& M$ T7 H& P1 k7 _
    72.                         <tx:method name="add*"    propagation="REQUIRED" />% z1 L4 k6 V( f. m
    73.                         <tx:method name="create*" propagation="REQUIRED" />; I1 ^. P6 k0 `+ Y3 O: b
    74.                         <tx:method name="insert*" propagation="REQUIRED" />
      : a# `4 v# x$ D) Q; F/ S! l( G: U
    75.                         <tx:method name="update*" propagation="REQUIRED" />: D$ N* Z9 f: B5 k8 T) F" F* X/ P
    76.                         <tx:method name="merge*"  propagation="REQUIRED" />( N- p8 g6 s( d6 Y/ S; |% f9 [3 i- f# [
    77.                         <tx:method name="del*"    propagation="REQUIRED" />) [4 Q/ `, _( m$ _: p
    78.                         <tx:method name="remove*" propagation="REQUIRED" />
      # z1 v8 U8 c4 v3 F8 h2 _
    79.                         <tx:method name="put*"    propagation="REQUIRED" />0 Y- k8 U* }! F5 Y$ E% E
    80.             <tx:method name="*" propagation="SUPPORTS" read-only="true" />  5 Q  o9 \2 n+ p* p' ^( ~
    81.         </tx:attributes>  ! G& J; |* R8 `! b+ N- f/ M
    82.     </tx:advice>
      * s" I( X3 U# c# J
    83. </beans>  
    复制代码
    spring-mvc.xml:/ H; O7 C( A5 v$ C
    6 G# K- {. K& z! w
    1. <?xml version="1.0" encoding="UTF-8"?>
      ) P& n% x; Y& P6 M! q8 o1 ~3 S
    2. <beans xmlns="http://www.springframework.org/schema/beans"9 Q4 X) s6 I1 Q" Y! Y1 X6 n
    3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"/ f! ~7 m4 ?& j, |+ R
    4.         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"/ s1 f5 `  ~$ |: V7 {- ~
    5.         xmlns:mvc="http://www.springframework.org/schema/mvc", P) P( D+ |) p! k, t4 e- w
    6.         xsi:schemaLocation="http://www.springframework.org/schema/beans  / L& C; r; W7 s7 O6 ^) r
    7.            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
      * Y6 q9 y0 O8 b" S5 V
    8.            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  / v: V. e) P! P: ~. E2 e
    9.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
      " O. ^9 R& [. g0 X
    10.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
      9 ?" a: J* J1 a) Y2 A
    11.            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
      8 l+ n# S' n+ D; C1 F9 L. o. X6 j
    12.     <!-- 自动扫描的包注解  -->, F' W1 w! @& X( ?. M+ }
    13.         <context:component-scan base-package="com.hoodo.rci" />. M; h1 P7 P! ?3 R1 ?/ E$ D/ L+ }* f
    14.         <!-- 自动注入  -->5 ]2 h4 F, Y) |9 Q3 w% g
    15.         <mvc:annotation-driven />4 X+ k; u8 ~/ K' {' T" {! p: F
    16.     <!-- 视图解析器 -->
        K. S" G: Q' c) W/ h2 W: a+ A
    17.         <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        Z' ~0 {! z; z' C1 q! e
    18.                 <property name="prefix" value="/WEB-INF/jsp/" />; {# w3 G, b% S. y0 j
    19.                 <property name="suffix" value=".jsp" />. J6 |0 D  d+ f, z1 v6 {
    20.         </bean>! ?* e0 m9 b0 a; P& K, ]# _2 T
    21.         1 K& Q( i; l% |( G! G2 a7 J5 H
    22.      <!-- 异常解析器 --># Y2 ^0 t9 |$ [2 c8 H' h
    23.    <!--  <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">9 @, R6 s" U, j3 F' ?+ Q
    24.         <property name="defaultErrorView" value="common/error" />+ s# ?# ~) [5 ?& t: d# D3 W
    25.    </bean> -->
      3 d; k! c) X6 e( W* c9 j1 x, O
    26.      
      6 |2 j/ ^7 k* k- t
    27.      <!-- 拦截器  -->
      # x) M8 h5 F! s. e1 v  a6 _) g
    28.         <!-- <mvc:interceptors>
      - g' G% F1 Q' \, ^- j& h' p/ u/ _
    29.             <mvc:interceptor>! A! J2 h4 D6 W7 s, w  K! V
    30.                <mvc:mapping path="/admin/*/*" />
      8 [; E# Q* G5 V" j" o! U$ `1 p  o
    31.                <bean class="com.filter.CommonInterceptor"></bean>0 Q& g1 j+ q8 y" q$ ]; `
    32.             </mvc:interceptor>( q$ e* W$ b* S" F; w$ v
    33.         </mvc:interceptors> -->
      ( Q, X4 L2 @! W8 d% }2 Q
    34. 1 C+ Q1 Y0 F6 U% J9 R# d
    35.         <!-- 上传文件相关的配置 -->' N. F3 x& d: E! l* I
    36.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
      2 p$ n& ~' n- P9 t/ T- H
    37.         <property name="defaultEncoding" value="utf-8" />
      : K9 t5 P( ~. Y, \0 f8 p
    38.                 <property name="maxUploadSize" value="104857600" />
      ! P3 [3 U6 N: N" m2 L7 j* L
    39.                 <property name="maxInMemorySize" value="4096" />" o6 l& u$ Q) E+ V/ _+ a; O
    40.         </bean>
      % s+ e# J" T' a; ^9 Y) _2 Y9 Q  S
    41. </beans>
    复制代码

    ' \5 z) t  \$ \) {
      a+ F2 ]8 `; t2 u- _% c7 Z% q' c/ h/ S% s( W" h, F  n
    SpringMVC+hibernate4.3+Spring4.1整合案例
    5 }7 c! R6 z  A! J
    5 w- W4 ^7 G, Z$ J5 t

    科帮网-Java论坛、Java社区、JavaWeb毕业设计 1、本主题所有言论和图片纯属会员个人意见,与本社区立场无关
    2、本站所有主题由该帖子作者发表,该帖子作者与科帮网-Java论坛、Java社区、JavaWeb毕业设计享有帖子相关版权
    3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和科帮网-Java论坛、Java社区、JavaWeb毕业设计的同意
    4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
    5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
    6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
    7、科帮网-Java论坛、Java社区、JavaWeb毕业设计管理员和版主有权不事先通知发贴者而删除本文


    JAVA爱好者①群:JAVA爱好者① JAVA爱好者②群:JAVA爱好者② JAVA爱好者③ : JAVA爱好者③

    1

    主题

    3

    听众

    341

    金钱

    四袋长老

    该用户从未签到

    沙发
    发表于 2016-03-17 21:46:03 |只看该作者

    ) ?* A# y9 W# K, P" |下来,学习一下。谢谢
    回复

    使用道具 举报

    woniu 实名认证   

    2

    主题

    0

    听众

    330

    金钱

    四袋长老

    该用户从未签到

    板凳
    发表于 2016-04-12 11:49:21 |只看该作者
    这个项目太棒勒!下下来学习下!
    回复

    使用道具 举报

    2

    主题

    0

    听众

    289

    金钱

    五袋长老

    该用户从未签到

    地板
    发表于 2016-05-05 16:00:00 |只看该作者
    下来,学习一下。谢谢
    回复

    使用道具 举报

    2

    主题

    0

    听众

    289

    金钱

    五袋长老

    该用户从未签到

    5#
    发表于 2016-05-05 16:00:11 |只看该作者
    下来,学习一下。谢谢
    回复

    使用道具 举报

    2

    主题

    0

    听众

    289

    金钱

    五袋长老

    该用户从未签到

    6#
    发表于 2016-05-05 16:00:44 |只看该作者
    感谢分享   ,
    回复

    使用道具 举报

    1

    主题

    0

    听众

    80

    金钱

    三袋弟子

    该用户从未签到

    7#
    发表于 2016-06-22 09:26:53 |只看该作者
    好资料,可以好好学习下
    回复

    使用道具 举报

    4

    主题

    0

    听众

    302

    金钱

    四袋长老

    该用户从未签到

    8#
    发表于 2016-09-26 16:41:42 |只看该作者
    看看。学习学习。谢谢楼主
    回复

    使用道具 举报

    46

    主题

    1

    听众

    584

    金钱

    三袋弟子

    该用户从未签到

    80后

    9#
    发表于 2016-10-30 11:15:32 |只看该作者
    SpringMVC+hibernate4.3+Spring4.1整合案例 [复制链接]
    回复

    使用道具 举报

    5

    主题

    0

    听众

    316

    金钱

    四袋长老

    该用户从未签到

    10#
    发表于 2017-08-14 08:49:01 |只看该作者
    不错不错不错,学习一下
    回复

    使用道具 举报

    快速回复
    您需要登录后才可以回帖 登录 | 立即注册

       

    发布主题 快速回复 返回列表 联系我们 官方QQ群 科帮网手机客户端
    快速回复 返回顶部 返回列表