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

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

动态微博

查看: 8181|回复: 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:5 V* p1 w* M, t) B% d$ W$ f

    3 x& H8 z7 n) G2 A4 M3 X
    1. <?xml version="1.0" encoding="UTF-8"?>  ; _, X9 U- S9 ^( `, w
    2. <beans xmlns="http://www.springframework.org/schema/beans"   
      ) E7 k+ R& }" [1 `. O) N/ ^: r8 O0 @
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   2 i/ o8 ?' X, W. f# r
    4.     xmlns:p="http://www.springframework.org/schema/p"  
      . b+ c" a7 ]- V* u  e" @+ k
    5.     xmlns:aop="http://www.springframework.org/schema/aop"   : F/ Y: a& {) C2 t- u5 i$ g' K5 Q  u2 ~: l
    6.     xmlns:context="http://www.springframework.org/schema/context"  ; i# s$ |- J+ x1 s* b' f; N
    7.     xmlns:jee="http://www.springframework.org/schema/jee"  7 {. Z6 k% X& u/ b: F
    8.     xmlns:tx="http://www.springframework.org/schema/tx"  
        ~4 u+ n, i1 M) c
    9.     xsi:schemaLocation="    ! @- S2 L, s2 {# J  b" r, e8 J
    10.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
      $ [  R  b8 `, {3 p( m
    11.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  5 g2 W- N" s# S- I7 D+ U( Q% R
    12.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
      % D( O3 R! f" l8 y/ r* }; F  B2 W0 K4 r
    13.         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
      ; h) t7 x& N, z$ m% j
    14.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
      ! ?4 w5 ^6 q. v0 m& `" P
    15.     6 M4 C) u3 E7 G# g6 O7 W- R
    16.     <!-- <mvc:annotation-driven /> -->
      $ c$ w- I# X1 N. t
    17.     <!-- 【配置视图解析器】 -->  3 M3 k5 Q2 Z- z' [! X; t) W! ~
    18.     <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->  
        f9 h1 D7 c. I1 I
    19.     <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 -->  / Z6 R3 y, Z! e9 d
    20. <!--    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
      - U* U8 f* v2 ?+ ?
    21.         <property name="prefix" value="/WEB-INF/jsp/"/>  
      $ S0 f/ B1 A: @
    22.         <property name="suffix" value=".jsp"/># g: R  T) J6 I' ^
    23.     </bean> -->2 V0 J6 H# y; U
    24.     9 L% ]: G2 m/ P0 h# Q* z
    25.     <!--  导入springMvc.xml配置文件 -->2 h) E8 _9 A  i% @. c
    26.     <import resource="classpath:config/spring-mvc.xml" />3 C, R( ^! ^$ R! f+ q% T( @
    27.     <!-- 加载数据库配置 -->3 [1 x+ s& [' R
    28.     <context:property-placeholder location="classpath:config/db.properties" />
      / V0 Z- {) k" t, b( ~
    29.         <!-- 加载数据源 -->5 X' m4 y+ [0 r- s
    30.         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      ) @& u! x# U* W/ B
    31.                 <property name="driverClassName" value="${db.driverClassName}" />) p1 _1 u+ S) S+ \
    32.                 <property name="url" value="${db.url}" />
      5 s+ N% z0 t  q  K
    33.                 <property name="username" value="${db.username}" />
      + |, H1 |' |2 ]3 U" x0 U5 a
    34.                 <property name="password" value="${db.password}" />+ @" b% ?! J5 F: ?& Z
    35.                 <property name="maxActive" value="${db.maxActive}" />, [0 e! L. p% X; T
    36.                 <property name="maxIdle" value="${db.maxIdle}" />5 f  T7 d: g2 a3 @1 B
    37.                 <property name="minIdle" value="${db.minIdle}" />' ^& q5 U& {" @+ W5 G5 z3 g
    38.                 <property name="maxWait" value="${db.maxWait}" />- E: l8 m+ z0 G1 e- \
    39.         </bean>
      9 C$ Q& Q6 W+ X# e
    40.     0 _$ H: T6 f4 U( \
    41.    
      , `0 ?+ C6 V/ x/ {! Y9 v3 j' }
    42.     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
      - p, K4 a* J: u4 H5 M
    43.         <property name="dataSource" ref="dataSource" />  % L+ f/ ]4 w2 G7 l* O
    44.         <property name="mappingDirectoryLocations">  
        Q% U- o1 p6 H" k; x6 l/ D0 w
    45.                   <list>+ b" p  _8 _3 W' W- I! y0 P7 v
    46.                                 <value>classpath:config/hbm/</value>
      - j$ w) s! n+ L1 q# f% Z1 N
    47.                         </list>2 b9 R. o7 w7 X* |+ e  n
    48.         </property>  ) o2 O4 h# M/ p: Y# h3 d
    49.         <property name="hibernateProperties">  8 f# W/ X, f, a9 Z' D6 j7 ?' r
    50.             <props>$ E5 h$ [. `8 n2 Z2 ^
    51.                                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>
      8 q  y% l  o0 \4 q
    52.                                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>/ M' _$ U5 ^4 {. f- r7 ~
    53.                                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
      9 Y2 b1 l) R5 R$ S3 C6 n
    54.                                 <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->& ^8 p* m2 R5 B% r( c
    55.                                 </props> 5 _9 ^8 ]$ f( \5 b4 l) E+ _5 R. o
    56.         </property>  
      / n/ n7 {: t! Z5 Q
    57.     </bean>, V. i4 ^: h4 F1 V) ]
    58.     3 g* A+ y* i' L9 G0 b- n: Y
    59.     <!-- 声明式事务 -->  
      $ F7 f" [% t2 ~$ l( v
    60.     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  4 ^0 W5 M* Q: r+ C
    61.         <property name="sessionFactory" ref="sessionFactory" />  
      1 n" f3 D2 q# k! S( _3 x, f  e4 Y
    62.     </bean>  * N; r  R- s5 b# V. {* n' \0 R
    63.          
      ; D$ q; B/ @& M! y* X$ J
    64.     <aop:config>  
      0 s; t7 J& O$ Z+ u3 s, z
    65.         <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />  ! p# z1 K- ^7 N$ \# ^
    66.         <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />  0 O4 N8 H4 G- J) H/ F4 W3 _- k
    67.     </aop:config>  8 d+ S6 c& Q& H2 m
    68.       
      9 e& R( M* I. T! E5 x2 B8 S
    69.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
      , Z- `. }  c: L. g6 P& [
    70.         <tx:attributes>  
      - ]8 j8 T& B* a2 P
    71.                 <tx:method name="save*"   propagation="REQUIRED" />, d# X( h! g0 z" a! s
    72.                         <tx:method name="add*"    propagation="REQUIRED" />" ]1 p$ }3 H6 m( q6 Z: P4 x& W
    73.                         <tx:method name="create*" propagation="REQUIRED" />
      + G, n; p: N, t+ ~+ b; h+ H% |7 g
    74.                         <tx:method name="insert*" propagation="REQUIRED" />
      4 O9 ~; ]# B, T1 `
    75.                         <tx:method name="update*" propagation="REQUIRED" />" a+ S5 x$ |  Z( `2 h6 V# L
    76.                         <tx:method name="merge*"  propagation="REQUIRED" />
      8 p' r! j. n9 v3 J6 R
    77.                         <tx:method name="del*"    propagation="REQUIRED" />) f* e1 M+ J. R& ]
    78.                         <tx:method name="remove*" propagation="REQUIRED" />: S9 L! ~, e2 F/ F" I
    79.                         <tx:method name="put*"    propagation="REQUIRED" />5 J9 o, Z! ~) h; i
    80.             <tx:method name="*" propagation="SUPPORTS" read-only="true" />  3 e4 q6 x3 B0 n  F* [
    81.         </tx:attributes>  5 G! p% w1 J, E7 c
    82.     </tx:advice> # {1 t! L4 E' G2 {0 |/ c
    83. </beans>  
    复制代码
    spring-mvc.xml:5 _7 ~7 b% f. W

      ?& q8 J; {, e4 u9 T; }9 d
    1. <?xml version="1.0" encoding="UTF-8"?>
      6 x; W- t. ]: ~9 b& Z9 v$ K9 A& ~
    2. <beans xmlns="http://www.springframework.org/schema/beans"
      2 N" F1 T5 ^: z$ s4 g
    3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      1 j& {3 H. ^( e  R
    4.         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
      8 _! u8 a" G  z+ a3 n5 N# D
    5.         xmlns:mvc="http://www.springframework.org/schema/mvc"
      9 }2 J; K( L" e" L2 S7 C6 S
    6.         xsi:schemaLocation="http://www.springframework.org/schema/beans  1 X8 ?1 s. C5 r
    7.            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  2 z: I+ _0 }2 k( x7 g0 J" M
    8.            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
      . W3 y; [; [1 D8 n* D6 F
    9.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
      0 t4 j( ]  z" X& p7 G& p
    10.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
      9 }# `6 a( O0 T: L
    11.            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">3 f! d, P  h% _; y- i1 j5 j
    12.     <!-- 自动扫描的包注解  -->
      ; P( l5 L9 E6 G. c5 j+ Y
    13.         <context:component-scan base-package="com.hoodo.rci" />
      2 O" l7 k: k. C2 u2 u; m% F. M
    14.         <!-- 自动注入  -->
      - ^6 D0 x# g/ t, A  X+ G. s! ?5 P
    15.         <mvc:annotation-driven />
      2 @* [$ i7 n* _7 T7 {0 C' k4 Z
    16.     <!-- 视图解析器 -->1 c" S7 Y% R5 m; S' p
    17.         <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      " F2 Q/ a/ l/ B
    18.                 <property name="prefix" value="/WEB-INF/jsp/" />
      & H1 ~4 y0 U0 k% Q; R- `+ V
    19.                 <property name="suffix" value=".jsp" />
      & k- j1 x/ I" O: O* M% \  D
    20.         </bean>
      9 U$ H8 u( a; _) _7 p" q+ U& m
    21.         / L- L6 Q- m+ X! i8 u( g
    22.      <!-- 异常解析器 -->
      ( n/ r3 G3 j' |9 U: ], H; N
    23.    <!--  <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
      ! Q3 \* u) g' p  q. `) t$ E
    24.         <property name="defaultErrorView" value="common/error" />
      " n+ t, [6 D7 l4 l2 \9 f7 ?4 i$ X! I
    25.    </bean> -->
      ' \8 }8 ~& ^8 F+ {$ e( Z
    26.      
      , i$ O* U' e8 b$ g
    27.      <!-- 拦截器  -->
      # N! @- ~+ ?2 d' a% l! h- x0 K
    28.         <!-- <mvc:interceptors>
      # p5 a4 q2 D; [3 z) D) }. M/ s$ I5 {
    29.             <mvc:interceptor>  r" [3 C0 d* q; `1 u3 O- m
    30.                <mvc:mapping path="/admin/*/*" />
      / d& K0 f1 b' [& ]. c+ _
    31.                <bean class="com.filter.CommonInterceptor"></bean>& N* o, ]% k( x4 {. r' }$ h6 `
    32.             </mvc:interceptor>
      % H# S+ ], X$ b' s
    33.         </mvc:interceptors> -->
      % w% N+ E6 O; s2 F3 k$ o' i7 P

    34. # O2 _5 |3 a" _" N
    35.         <!-- 上传文件相关的配置 -->$ u" r& i) N7 ?! s4 d! N
    36.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
      8 \6 g# A; g2 N1 G
    37.         <property name="defaultEncoding" value="utf-8" />
      6 S% [5 j4 S. r3 _2 {. V
    38.                 <property name="maxUploadSize" value="104857600" />5 {0 w8 F4 g9 q% ?% n: k5 L
    39.                 <property name="maxInMemorySize" value="4096" />
      7 D# r. `" f. \1 a1 }: k% v
    40.         </bean>( x; b1 A; e% q3 e; n
    41. </beans>
    复制代码
    9 I9 f) ?! O# G9 |, [; _
    " d/ ~) y( q- k. @7 F9 z
    9 }! }3 @- u4 u" A/ @
    SpringMVC+hibernate4.3+Spring4.1整合案例
    ! o  l) @& I; |1 E
    ( Z8 J& t) F6 f* u

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

    5 t- ~. `" R: L. K) t7 T" c6 u! r+ d5 ?# 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群 科帮网手机客户端
    快速回复 返回顶部 返回列表