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

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

动态微博

查看: 8178|回复: 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:, f" }' w* `: K4 S* [0 ~

    2 W) p, I4 e2 h2 b0 G- ^
    1. <?xml version="1.0" encoding="UTF-8"?>  
      ! ^! c% }" g* s+ _/ Z2 Z
    2. <beans xmlns="http://www.springframework.org/schema/beans"   
      1 r) `5 ?1 V' |7 ~3 i! v
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   + ?/ A. T' z) p! N* b5 a& ^
    4.     xmlns:p="http://www.springframework.org/schema/p"  ) [3 P. x; s9 f7 k# W& y& c
    5.     xmlns:aop="http://www.springframework.org/schema/aop"   
      3 c# ?& @7 y% t0 Q4 k' Q
    6.     xmlns:context="http://www.springframework.org/schema/context"  - C: s) P1 X7 s  V# ^7 F
    7.     xmlns:jee="http://www.springframework.org/schema/jee"  
      - g5 F" V) \3 e& n2 k' T
    8.     xmlns:tx="http://www.springframework.org/schema/tx"  & `, S8 ?9 d' ?  F* m  j$ E7 u
    9.     xsi:schemaLocation="   
      9 q3 E! m  e+ m7 x/ Q% Q
    10.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  7 m5 R$ e. g/ [' }( c. U8 V" e* C
    11.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
      ; q1 n4 K! s" |' y
    12.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
      % m% d) k$ J) _
    13.         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
      . N: {1 t: D; F. m( @" ~7 d
    14.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
      - J2 Z" `" u+ f; @% g
    15.    
      6 l; E  n5 X; r' R( \/ h2 I) e
    16.     <!-- <mvc:annotation-driven /> -->3 o- g6 c7 c5 b  P. i' o
    17.     <!-- 【配置视图解析器】 -->  
      - s/ f, b8 z! F% i( O- F- S0 R
    18.     <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->  . U; d, m( ~, c3 z
    19.     <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 -->  
      ! f" g8 r' @+ S0 E: v
    20. <!--    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
      0 ]9 c! h  |6 N1 }  I# N% ^" w
    21.         <property name="prefix" value="/WEB-INF/jsp/"/>  
      6 P% A' B3 r; ~% o& o1 O/ x. ?
    22.         <property name="suffix" value=".jsp"/># O/ Z* _4 a, b" w. b) J- X
    23.     </bean> -->& P; h/ T; ~1 Y( d4 b
    24.     ( ~! M8 f: u' O( s6 e" ]4 ?9 x
    25.     <!--  导入springMvc.xml配置文件 -->
      7 Z9 s  ~1 s6 P& h
    26.     <import resource="classpath:config/spring-mvc.xml" />
        p/ x' O1 f  Q& W$ r1 ?8 a; m
    27.     <!-- 加载数据库配置 -->2 C4 t+ Q; H; d1 b1 g8 k
    28.     <context:property-placeholder location="classpath:config/db.properties" />
      3 a; v2 D' D  h4 m4 c1 q
    29.         <!-- 加载数据源 -->
      : Q# f; [- k2 t' M2 z2 p" l& J' W
    30.         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">; c5 s# K. x4 p+ z" P" E+ Y
    31.                 <property name="driverClassName" value="${db.driverClassName}" />
      ' u4 f" B7 }( G& Q
    32.                 <property name="url" value="${db.url}" />
      ; V% r9 b9 \* B9 [, K) H
    33.                 <property name="username" value="${db.username}" />4 j6 c9 O- E6 L5 [
    34.                 <property name="password" value="${db.password}" />7 N: F% R3 ?+ {" V2 N
    35.                 <property name="maxActive" value="${db.maxActive}" />' ^/ [& ^1 f5 @5 {+ Y/ ^( r
    36.                 <property name="maxIdle" value="${db.maxIdle}" />
      $ j8 Z& W) r8 E- F# C4 c8 Z
    37.                 <property name="minIdle" value="${db.minIdle}" />9 R5 q0 m( O" R
    38.                 <property name="maxWait" value="${db.maxWait}" />* t; m# e( C( {% [, E
    39.         </bean>
      7 w* ^; f1 w4 Y8 W  \( c* {
    40.     , m# v5 D% b1 j: }
    41.     ) u! b8 I  {  F* Y4 W: I
    42.     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  % p2 D8 q- p$ ?) ?( Q. [
    43.         <property name="dataSource" ref="dataSource" />  : N1 o4 l8 }3 u3 @2 I( N
    44.         <property name="mappingDirectoryLocations">  
      5 M6 l( {. F) a- Y, C2 q
    45.                   <list>  G* `% g+ a- w( f( u) p. D
    46.                                 <value>classpath:config/hbm/</value>
      / y; R9 E) }4 e6 ^, g9 Z2 h
    47.                         </list>
      . V* Z; x4 X# m! l9 K1 I) R: B
    48.         </property>  
      3 _, l0 J& j- v! C/ p7 ?# V* ?
    49.         <property name="hibernateProperties">  ; w5 S. \/ T( H2 V( V& _2 w; `
    50.             <props># [- x3 p, u9 e. q$ W6 \
    51.                                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>& m; W. q4 m- l1 I
    52.                                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
      ' f9 Q* E5 T6 m
    53.                                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>1 _# E5 S% Z, R# o; N/ Q/ n2 X
    54.                                 <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->
      - Z( {/ @* M$ @. a" k
    55.                                 </props>
      % F. @0 m' [" V" c' m  M9 h
    56.         </property>  2 o) l8 O( _) k( k+ ^3 |0 _
    57.     </bean>
      7 f# x3 H+ x+ _6 e$ l6 I" Q
    58.    
      , m$ _$ {4 X( r+ k( n% }1 O
    59.     <!-- 声明式事务 -->  
      0 a$ n, B. I+ j1 l/ z& {9 A
    60.     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  3 B, g& W7 E3 y
    61.         <property name="sessionFactory" ref="sessionFactory" />  : T5 a4 ]3 q+ L( Z- X- x; a( l
    62.     </bean>  : ~( R" \; t' Y$ h. ^
    63.          
      : r  @* M# h* k. @6 c: p4 q8 F& s
    64.     <aop:config>  
      ' r7 j5 k# Y. T  r3 h
    65.         <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />  
      - z3 l5 }; w5 @4 @& \6 K- K8 |( ~: d
    66.         <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />  
      , j: ?0 w2 j7 _) t4 q# L* O
    67.     </aop:config>  
      6 V3 L! ?5 u" I* r* w
    68.       
      ' L3 \- t' _+ q) C
    69.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  & l) l+ n! K! h7 w& V
    70.         <tx:attributes>  / W. w; D8 d: s0 u" S* j8 Q
    71.                 <tx:method name="save*"   propagation="REQUIRED" />
      / e* p* o) y2 m) R
    72.                         <tx:method name="add*"    propagation="REQUIRED" />
      ; e8 Y6 w, B4 a( A" d
    73.                         <tx:method name="create*" propagation="REQUIRED" />  ?2 r. m) ~# @/ Y2 P1 E( m2 L
    74.                         <tx:method name="insert*" propagation="REQUIRED" />
      + _8 y( H" Z$ Z6 x
    75.                         <tx:method name="update*" propagation="REQUIRED" />1 |. E  A% [# @& d
    76.                         <tx:method name="merge*"  propagation="REQUIRED" />' T. X. I. p% Z; H, M5 |
    77.                         <tx:method name="del*"    propagation="REQUIRED" />
        I5 b/ b' P" O0 l& [
    78.                         <tx:method name="remove*" propagation="REQUIRED" />+ s# t, j9 }3 P: f7 H$ d
    79.                         <tx:method name="put*"    propagation="REQUIRED" />* ]( I* r; O# h4 D: x/ r
    80.             <tx:method name="*" propagation="SUPPORTS" read-only="true" />  0 I9 h6 }3 D5 G2 X$ `' \% u; Y/ h* z
    81.         </tx:attributes>  + _/ r; v4 E3 h1 }& R. t# `" Y
    82.     </tx:advice>
      3 C/ H6 k- M8 H5 z  A3 s) X
    83. </beans>  
    复制代码
    spring-mvc.xml:
    # e8 _+ d. x' Y9 G( Z1 S5 d+ _* ?, t
    1. <?xml version="1.0" encoding="UTF-8"?>
      / x( q3 N  f3 b9 ], K
    2. <beans xmlns="http://www.springframework.org/schema/beans"
      3 f- P8 u( v! M" E& s9 z5 ^
    3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"4 |& e. q% T5 I* Z
    4.         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
      4 N  H* b$ m- m9 x/ ~
    5.         xmlns:mvc="http://www.springframework.org/schema/mvc": J+ A3 e/ ^: d- D8 c; \9 p2 E
    6.         xsi:schemaLocation="http://www.springframework.org/schema/beans  
      , i+ l( i; D3 C, e& s2 s" r
    7.            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
      ! t: H2 _% ~7 f& w2 E. @2 {+ O
    8.            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  $ J8 ?. G' a9 X# S& c
    9.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  , ~9 Q  M) p9 w- h+ S8 ]
    10.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd5 k! B6 w! x& I% g
    11.            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">9 j$ a. v5 ?; ~
    12.     <!-- 自动扫描的包注解  -->
      , F: o( S  K9 p+ |' V
    13.         <context:component-scan base-package="com.hoodo.rci" /># j5 K2 B4 g7 e# p- J2 y6 @' E
    14.         <!-- 自动注入  -->
      ( O; e* X' _. E+ C3 U
    15.         <mvc:annotation-driven />
      ' n$ p) H6 Y! S9 x; E
    16.     <!-- 视图解析器 -->, d8 ], k0 T! F; V7 ]
    17.         <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        o. j" t  N* C
    18.                 <property name="prefix" value="/WEB-INF/jsp/" />/ n1 T% H. A% N1 c+ X
    19.                 <property name="suffix" value=".jsp" />
      ' H8 h; ]$ K( E* n: e- U' D
    20.         </bean>
      3 i0 b7 Z" B  E* N0 N
    21.         
      1 h: M* |7 A8 _& _+ f1 O
    22.      <!-- 异常解析器 -->8 g5 ?1 I) Y& ^/ d$ Z& Y1 B
    23.    <!--  <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        M. u% \0 X7 Z- z9 p
    24.         <property name="defaultErrorView" value="common/error" />% d3 d7 j% K! S0 D/ V' X" v2 }
    25.    </bean> -->+ \8 a' \: ^# [5 z# P+ Y; g
    26.      1 R$ ~4 j  r7 [4 F  Y
    27.      <!-- 拦截器  -->
      : P  A' W! b& `
    28.         <!-- <mvc:interceptors>
      : F1 u5 d& s5 N' n5 J
    29.             <mvc:interceptor>
      ( ~6 B7 }" `( |. t
    30.                <mvc:mapping path="/admin/*/*" />
      5 F: c! B* E4 J# K
    31.                <bean class="com.filter.CommonInterceptor"></bean>0 J4 q" D& R& _$ P5 i$ ~, V/ }3 \
    32.             </mvc:interceptor>  `/ X. e1 I# m6 r6 A6 X8 X5 I
    33.         </mvc:interceptors> -->
      5 a% _8 Z! E8 [) A/ `9 @
    34. ( y% V5 q. Z' e+ P2 K3 g* `
    35.         <!-- 上传文件相关的配置 -->: d( w2 E3 I* W. R5 p3 x+ e( p
    36.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">" e/ `/ E4 Z) j# Y
    37.         <property name="defaultEncoding" value="utf-8" />
      , x, {/ ~6 {: i1 ?4 p, X
    38.                 <property name="maxUploadSize" value="104857600" />
      ( N- n! |% X. K$ b( p  w: w
    39.                 <property name="maxInMemorySize" value="4096" />
      7 ]+ b( v. k- |$ t8 t% Y% D- f, o- T
    40.         </bean>
      ' G% s; \( Q: c% I2 |. t
    41. </beans>
    复制代码

    % f( U0 a. y+ O0 F0 j% H4 ^3 a8 p( x. J2 f" H: Y

    8 j& k- B7 a8 A" m  KSpringMVC+hibernate4.3+Spring4.1整合案例

    1 J) s% W6 G3 Q2 M0 W+ h
    5 h6 R$ d# w* f9 a# f& b: y2 U  o

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

    ) n; y' ~% q* |- N/ k: Y, M下来,学习一下。谢谢
    回复

    使用道具 举报

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