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

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

动态微博

查看: 8194|回复: 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:# t2 U: o5 j, v% a+ O, e, q$ k

    - `( @6 J# ]5 t2 q' [
    1. <?xml version="1.0" encoding="UTF-8"?>  9 |% E# u# C6 e# F% p- j
    2. <beans xmlns="http://www.springframework.org/schema/beans"    6 r" e& c5 }7 N) |& W
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   - }$ F. r5 j6 W$ \6 N
    4.     xmlns:p="http://www.springframework.org/schema/p"  7 F9 f" e+ u4 H3 p5 n- L
    5.     xmlns:aop="http://www.springframework.org/schema/aop"   
      9 F! @9 H3 [2 C& s) S
    6.     xmlns:context="http://www.springframework.org/schema/context"  6 p1 r: T2 E$ J4 `8 l
    7.     xmlns:jee="http://www.springframework.org/schema/jee"  ; Y# o* w" I7 {! t! Z
    8.     xmlns:tx="http://www.springframework.org/schema/tx"  5 ]# P  P% E$ A7 V$ x" N
    9.     xsi:schemaLocation="    1 \) M4 m  y5 F! D4 b) o% O3 ~# T, s
    10.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  $ i! t3 {1 h$ D2 A7 I
    11.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  0 T$ Q: ~- T) D/ t
    12.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
      . A( ?8 g1 @) u) C% W3 e$ h- s
    13.         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
      6 a- k9 G, S' b! R' ~1 H. x
    14.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> 9 @" g/ ?+ _; T) n5 Y
    15.    
      % V0 }) [8 r0 c0 b. z
    16.     <!-- <mvc:annotation-driven /> -->
      8 A' a2 G/ R  K" {( s# M
    17.     <!-- 【配置视图解析器】 -->  
      . v: \- B. T" H% ]! B
    18.     <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->  
      - m6 `2 f  o" J& W  F! w8 o" E% ^" }
    19.     <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 -->  5 j/ x, U; i' l3 ?2 S
    20. <!--    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  : O8 x% x/ \/ Y7 b% G' L# H  Z- _
    21.         <property name="prefix" value="/WEB-INF/jsp/"/>  
      + A7 h. ~4 K; |& a& y3 s9 `
    22.         <property name="suffix" value=".jsp"/>
      : S  u2 A7 i; V, l8 L3 A
    23.     </bean> -->* n5 ~7 t3 ~( k* J
    24.     # S, I$ q2 B' }  ^" M+ U
    25.     <!--  导入springMvc.xml配置文件 -->
      2 S1 y0 [+ Z; w8 {0 r
    26.     <import resource="classpath:config/spring-mvc.xml" />
      , j/ _" n6 r# \2 x! b( q$ T6 k; b
    27.     <!-- 加载数据库配置 -->& }% D) s. U1 k; e' ^+ Y
    28.     <context:property-placeholder location="classpath:config/db.properties" />5 m; X( m, V7 d  s
    29.         <!-- 加载数据源 -->2 \  z! ?8 A" X- @1 x  v6 \
    30.         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">6 V" r- f+ _( s" J# N0 |
    31.                 <property name="driverClassName" value="${db.driverClassName}" />
      2 z+ o4 D% C6 A$ n7 x: F" w
    32.                 <property name="url" value="${db.url}" />
      ! L  y  [, L3 Z+ a. L1 H, J! D
    33.                 <property name="username" value="${db.username}" />
      % n$ C1 I+ `& ]& H* }/ p
    34.                 <property name="password" value="${db.password}" />
      + L9 v4 e! H0 p: `/ i1 S4 Y
    35.                 <property name="maxActive" value="${db.maxActive}" />
      ! W/ k7 C2 S0 Z# T
    36.                 <property name="maxIdle" value="${db.maxIdle}" />0 S4 b5 ]# n: j; M0 h% G. f8 H
    37.                 <property name="minIdle" value="${db.minIdle}" />% t) Z. s: M4 Q6 M3 i
    38.                 <property name="maxWait" value="${db.maxWait}" />4 A& a; k" z6 y( I" O  q7 X
    39.         </bean>/ h2 }0 H- d' U9 Q2 o" r2 N
    40.     ; ^& H& W0 ~5 O# \- |9 C+ P% f' X
    41.    
        G( I6 v. k8 }: L" C
    42.     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  % X- A' u; S7 v$ k' S  l
    43.         <property name="dataSource" ref="dataSource" />  
      * w* n5 O! y* w* Q
    44.         <property name="mappingDirectoryLocations">  
      2 |7 x9 G/ `' F* Y& O# Z% Q
    45.                   <list>0 x; w( Q' ^2 d1 M% t
    46.                                 <value>classpath:config/hbm/</value>; n) H0 O3 D/ r5 ]
    47.                         </list>
      2 \$ ?+ p. I6 X' I# y& Q
    48.         </property>  ) ~; w- e' O% v1 t4 h' H& Q% k$ E* V
    49.         <property name="hibernateProperties">  # z+ r" R( a: ^. E% d
    50.             <props>
      , O) @! C* I/ x, b7 O4 w. n1 n6 V, x
    51.                                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>
      ) F. |( @9 n5 b6 P
    52.                                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>1 F4 M) k) A  O* ]4 ~' w
    53.                                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>, _. E# Z# A1 J, i
    54.                                 <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->
      0 n9 v; }7 m/ X/ ~
    55.                                 </props> 2 A: W* D. W# `2 _2 T
    56.         </property>  
      - N$ g2 h* }; w8 a
    57.     </bean>. _( l' N7 o& v9 H( n
    58.     ) ?+ [* W6 J8 Z/ J; n+ v
    59.     <!-- 声明式事务 -->  : g; q* o8 X6 K. W  i
    60.     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
      8 }8 t- {: q6 q
    61.         <property name="sessionFactory" ref="sessionFactory" />  
      , ^1 D3 h% ?+ d) D6 F+ k
    62.     </bean>  * q, s& m* R: f! e, N4 m! S/ H
    63.          
      ( ]( e( u1 Y: }
    64.     <aop:config>  
      4 }, l6 I+ w# d# _
    65.         <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />  
      / l; O1 x% |0 X  [0 M
    66.         <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />  ! v) ?% }) H, n- c# z, {
    67.     </aop:config>  
      2 J* D) p5 d5 D5 d) r3 ^
    68.       
      : S2 I0 L0 _) n( x* ?' ?
    69.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  " M- {+ e; R# `% {4 }4 Y
    70.         <tx:attributes>  
      # J' V8 r; B1 V8 N; ^
    71.                 <tx:method name="save*"   propagation="REQUIRED" />( O5 h, N9 f8 G5 l9 A
    72.                         <tx:method name="add*"    propagation="REQUIRED" />
      . Q: [6 h5 o" b
    73.                         <tx:method name="create*" propagation="REQUIRED" />* \- L# B; G. S9 t5 Y+ B' A* f0 X
    74.                         <tx:method name="insert*" propagation="REQUIRED" />
      : u6 Y  M& \" F( E. `7 K
    75.                         <tx:method name="update*" propagation="REQUIRED" />
      % |$ ]" ?% p  ^! V0 d
    76.                         <tx:method name="merge*"  propagation="REQUIRED" />( s1 h# ^6 G2 r/ A
    77.                         <tx:method name="del*"    propagation="REQUIRED" />
      5 D+ U$ `% U* e3 @. o9 V
    78.                         <tx:method name="remove*" propagation="REQUIRED" />, k6 T+ M( v& f! K& D$ V* G7 U( {9 u
    79.                         <tx:method name="put*"    propagation="REQUIRED" />
      3 Q" O# m3 R  p. I" l
    80.             <tx:method name="*" propagation="SUPPORTS" read-only="true" />  
        J6 {; b" i6 l5 N  `6 s/ {
    81.         </tx:attributes>    s3 |. `2 g4 z1 b
    82.     </tx:advice> : b8 `3 _3 C0 [  f/ j2 D5 a: f& Y% |
    83. </beans>  
    复制代码
    spring-mvc.xml:
    ! g) g4 C: g% N) E. F- n" B. e0 w$ W8 G) W. F
    1. <?xml version="1.0" encoding="UTF-8"?>
        p) l) x: \) A. z5 D8 d* D( K
    2. <beans xmlns="http://www.springframework.org/schema/beans"
      ' a7 Q; N; ~4 f  U0 s4 s; m$ D  D
    3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context") C. q3 d; j; H/ q" D0 X
    4.         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
      6 F0 h" u$ |( X3 Z% M
    5.         xmlns:mvc="http://www.springframework.org/schema/mvc"7 y2 |. i) K/ X3 p$ }1 z
    6.         xsi:schemaLocation="http://www.springframework.org/schema/beans  
      ! M- g  O9 _9 G+ T- V) _7 d. W
    7.            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
      , x3 E8 g/ G0 @7 G) p1 P  D
    8.            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
      0 z! N7 H9 U! j
    9.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  / R% \; O, @+ J2 A# z. Z
    10.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd) o' v5 N0 x: J* u; o. X# J
    11.            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">4 g4 _7 o' x# M( E7 T* }
    12.     <!-- 自动扫描的包注解  -->! `; u, F6 O1 J. V2 `
    13.         <context:component-scan base-package="com.hoodo.rci" />& o8 G$ i' k7 C+ J; `* w8 b
    14.         <!-- 自动注入  -->
      " c( j, [0 }' e( D1 \
    15.         <mvc:annotation-driven />4 V: ~( `+ [7 ?$ v3 v- J' }* s
    16.     <!-- 视图解析器 -->: E. x' D% p' Z/ R& j4 J) W. C4 ^( S
    17.         <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">) V; }4 H! x0 A5 ?7 n. Z2 L$ D9 \
    18.                 <property name="prefix" value="/WEB-INF/jsp/" />4 O6 r+ _% d: `' r" _, H
    19.                 <property name="suffix" value=".jsp" />5 t5 }0 b( J3 q. V5 `
    20.         </bean>
      * q/ c1 L8 l7 [5 ?7 A) n* G
    21.         ' `7 L  E. @( I
    22.      <!-- 异常解析器 -->2 P) P1 H) I* {$ V8 v# _) Q, Q
    23.    <!--  <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
      % L0 i# g( s+ s
    24.         <property name="defaultErrorView" value="common/error" />% z- n5 D0 t; V! ^2 V
    25.    </bean> -->9 m2 F7 N8 d; {( }, F% [- m2 J
    26.      
      3 `- `; ^/ h2 a( |% n& {
    27.      <!-- 拦截器  -->
      % U1 N: p1 X6 r! b
    28.         <!-- <mvc:interceptors>+ ?4 Z% p% Y% S$ ^$ S# B, ?$ ]
    29.             <mvc:interceptor>: A4 ^! E* N" C/ z9 G
    30.                <mvc:mapping path="/admin/*/*" />7 Z  T7 M! u* M2 b! u) n
    31.                <bean class="com.filter.CommonInterceptor"></bean>9 Z/ S* t* X1 @1 a/ W+ R
    32.             </mvc:interceptor># K4 ?- H$ P; Q+ q8 ?6 y% k
    33.         </mvc:interceptors> -->4 w- s" l! E; e

    34. / U/ H# z- t: J: S, g7 D
    35.         <!-- 上传文件相关的配置 -->
      6 _$ Q5 ?& q7 v* q* ~# |% p
    36.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">( U& K" _' Y& g/ ?1 g  O! Y
    37.         <property name="defaultEncoding" value="utf-8" />
      , I0 X0 A& q3 l5 c3 ~5 z
    38.                 <property name="maxUploadSize" value="104857600" />
      / N, p9 \5 A8 m: y4 ~5 ]+ d
    39.                 <property name="maxInMemorySize" value="4096" />
      $ _( B0 I$ ^2 l* C( ]" d2 n5 T
    40.         </bean>
      $ {9 O+ X6 d. j+ q/ I; r/ Z
    41. </beans>
    复制代码

    . c7 g( _* C+ j3 ]. M4 k+ n8 p- v4 A
    7 W* B6 d  L2 p) @8 x3 t6 B# s/ |5 }! R) p
    SpringMVC+hibernate4.3+Spring4.1整合案例

    * O; z* C7 B# Q9 ?
    - B/ s* ~( k" R% y. `1 [4 a

    科帮网-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 |只看该作者

    1 H% R$ i4 k: n8 \; e7 u下来,学习一下。谢谢
    回复

    使用道具 举报

    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群 科帮网手机客户端
    快速回复 返回顶部 返回列表