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

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

动态微博

查看: 8182|回复: 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:7 \- D/ ~9 {7 r8 K" F

    / H4 _0 J* k2 {" @; h5 I
    1. <?xml version="1.0" encoding="UTF-8"?>  : A0 R% a) o6 |3 v8 F! A1 z
    2. <beans xmlns="http://www.springframework.org/schema/beans"    / ]: Z, I6 I2 d. D6 W- d
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   ( M' M, e/ W- x1 n7 o
    4.     xmlns:p="http://www.springframework.org/schema/p"  8 n* z0 Y" ]1 ?( U% y/ e
    5.     xmlns:aop="http://www.springframework.org/schema/aop"   - J3 p, n* C/ I8 t% d
    6.     xmlns:context="http://www.springframework.org/schema/context"  
      0 L  r$ ~( z: n  Z5 j
    7.     xmlns:jee="http://www.springframework.org/schema/jee"  
      ! }6 s) a+ M3 Q
    8.     xmlns:tx="http://www.springframework.org/schema/tx"  
        \0 R' T) O" i- a
    9.     xsi:schemaLocation="   
      + L  V: ~6 ~% c- C9 u& @5 A( c; b
    10.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
      ( r" R$ Q3 c* j
    11.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  / R" \5 M/ z; ]. V, U# h
    12.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  % o$ ^% R  i* d+ Q, Q
    13.         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
      % z! K+ P+ H! j& V3 E" E/ j
    14.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> 3 m& K! {" }6 R4 v* a! F
    15.     ; s+ n4 U: V" z8 G* n6 N8 v
    16.     <!-- <mvc:annotation-driven /> -->
      & \2 d* q- @8 b" I7 O; U
    17.     <!-- 【配置视图解析器】 -->  2 m  r8 s, G5 q
    18.     <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->  
      " w1 t/ k& x* M+ F0 \% u$ b
    19.     <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 -->  $ h% N. |7 q7 o+ R* C9 I$ r2 D
    20. <!--    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
      8 R7 M$ E* `8 d
    21.         <property name="prefix" value="/WEB-INF/jsp/"/>  ( e- B$ F. P9 s/ O: K- n
    22.         <property name="suffix" value=".jsp"/>, X& Z" r: u4 m  s
    23.     </bean> -->
      7 I1 I9 r3 e+ I& V
    24.     8 X1 x' p2 C/ m( y" S! @
    25.     <!--  导入springMvc.xml配置文件 -->
      - a8 f% E5 x1 ]0 e; B6 J0 M2 Q" z
    26.     <import resource="classpath:config/spring-mvc.xml" />
      / @2 T  v4 {5 K9 q- k
    27.     <!-- 加载数据库配置 -->2 O. n$ o# O& \) }
    28.     <context:property-placeholder location="classpath:config/db.properties" />
      8 w" _! ^% `. `) u) ?$ ?
    29.         <!-- 加载数据源 -->: O6 A" ]* |& S: `7 G
    30.         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      8 }. q+ t+ O: Q$ V
    31.                 <property name="driverClassName" value="${db.driverClassName}" />1 X$ ^6 B3 L# O* Y- e
    32.                 <property name="url" value="${db.url}" />. w, U; S# ]$ g. c  \5 y: S0 F
    33.                 <property name="username" value="${db.username}" />
      ( m7 w5 b) }9 L" U9 s
    34.                 <property name="password" value="${db.password}" />0 [9 ~- o; r+ t% ]% d! l/ o# d
    35.                 <property name="maxActive" value="${db.maxActive}" />
      * n5 D0 s' h  o: G- s4 `3 O5 \
    36.                 <property name="maxIdle" value="${db.maxIdle}" />
      8 V0 T4 _: w+ B+ T) r
    37.                 <property name="minIdle" value="${db.minIdle}" />9 E- u7 B: K9 U! }2 D- I
    38.                 <property name="maxWait" value="${db.maxWait}" />
      5 @: K2 b) T: H
    39.         </bean>
      ) }, M3 m. }9 B/ a) u
    40.       E5 p& m* t: V& X: F% o- O% f: w
    41.       {: @6 V- Q% _
    42.     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
      1 I' G1 u+ Z+ p) I0 m
    43.         <property name="dataSource" ref="dataSource" />  9 a! |' R; D, L
    44.         <property name="mappingDirectoryLocations">  9 i" v, s6 Y" Q  b+ I
    45.                   <list>
      # R5 \* z+ c8 u7 S7 v2 X& Q6 L
    46.                                 <value>classpath:config/hbm/</value>
      . g6 V5 o: J5 c
    47.                         </list>2 N( Q6 k4 B+ C
    48.         </property>  
      5 e  h3 u# P& b' S7 r9 n$ J  N
    49.         <property name="hibernateProperties">  
      , n3 {# v+ [2 F& _  s/ L
    50.             <props>& q* ^9 {4 a0 e3 j. P
    51.                                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>
      + C) Z' G# _8 Z- N  l9 i
    52.                                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
      4 p  K$ P6 v3 }$ _# U- l9 Y( }
    53.                                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>  g1 x0 d0 W$ S
    54.                                 <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->
      7 ~" o2 ~9 g  D3 D" x: K/ t3 B
    55.                                 </props>
      - d( ^+ D4 x9 u5 p- ]# Q8 y
    56.         </property>  
      ! ]6 `1 K5 q  @
    57.     </bean>+ u) k# u4 ?/ U3 \, M
    58.    
      $ d" q  t9 R; g
    59.     <!-- 声明式事务 -->  ( z; x/ I) T4 m. ~! K
    60.     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  ( i2 S1 w0 x- T- ^; n- W
    61.         <property name="sessionFactory" ref="sessionFactory" />  
      ( s: j' p; I$ I
    62.     </bean>  * ^& W3 z9 e+ s2 T; t7 l2 c
    63.           - J: U/ C: y- t1 H$ P! r4 C0 B4 G
    64.     <aop:config>  . ^  d7 v: j  [3 l/ k( M6 E
    65.         <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />  
      2 p( F/ h5 h3 _
    66.         <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />  3 d& Z& n- ]& D; X6 O
    67.     </aop:config>  * `8 Z0 p( k) e- g2 M) B
    68.       5 k% s- f+ Q& ~: M& O7 f
    69.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  " \6 ?# b5 N5 c
    70.         <tx:attributes>  
      4 h* u9 C0 W( O" [& k2 H1 s# Y) R
    71.                 <tx:method name="save*"   propagation="REQUIRED" />" B: m) s# y$ z) E- W% b
    72.                         <tx:method name="add*"    propagation="REQUIRED" />& J) }& O+ H& p( R& L
    73.                         <tx:method name="create*" propagation="REQUIRED" />
      " Y1 A2 P$ b2 c& c& L
    74.                         <tx:method name="insert*" propagation="REQUIRED" />6 l3 l7 I, h* x) I* }; e0 f# E
    75.                         <tx:method name="update*" propagation="REQUIRED" />! B! Z/ b0 i: w) G7 X6 ?
    76.                         <tx:method name="merge*"  propagation="REQUIRED" />
      $ a; ~7 t& b* j$ S( [9 z" {
    77.                         <tx:method name="del*"    propagation="REQUIRED" />
      ( s5 x4 L" `$ d
    78.                         <tx:method name="remove*" propagation="REQUIRED" />
      2 H2 h6 i2 K6 }& F
    79.                         <tx:method name="put*"    propagation="REQUIRED" />
      7 l% v" o2 E0 R; `. A0 f
    80.             <tx:method name="*" propagation="SUPPORTS" read-only="true" />  
      . D& f: K# l" H; e* @+ ^' l
    81.         </tx:attributes>  
      : }/ _, D2 v' K/ R2 L' d
    82.     </tx:advice> + m1 _" t! J' D0 U$ O& D
    83. </beans>  
    复制代码
    spring-mvc.xml:$ f. |$ f& e+ R6 M1 F

    ) E; F9 Y* Q5 Z
    1. <?xml version="1.0" encoding="UTF-8"?>
      ! w# A7 o# c+ ]3 a4 N
    2. <beans xmlns="http://www.springframework.org/schema/beans"! D5 o! x- \) D0 S: R3 f. R  [2 ?
    3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      ; W9 {0 `' E7 S! t9 [
    4.         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"( p  d7 H6 @4 L  j: g5 E- ]
    5.         xmlns:mvc="http://www.springframework.org/schema/mvc"
        }1 |/ t4 T9 S6 x+ d/ A# h
    6.         xsi:schemaLocation="http://www.springframework.org/schema/beans  3 `. u  O  m5 ~! B9 b
    7.            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  / J4 y$ E  @& X+ b! K) V- A' D# H
    8.            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  0 L. H  ]6 _9 q0 z* w* |
    9.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  ' ?7 u; e+ S4 }
    10.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" A! |* ~+ G/ [3 t
    11.            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
      : U$ W+ I  r2 P2 q! q% I0 _; N
    12.     <!-- 自动扫描的包注解  -->' t" ^! z6 D5 ~! V! d
    13.         <context:component-scan base-package="com.hoodo.rci" />  {! f6 c, |" @6 W( P+ ^
    14.         <!-- 自动注入  -->2 ~6 e8 m  v) g: o# f9 X" A
    15.         <mvc:annotation-driven />
      4 ^! ?4 N3 n: A6 G' c$ a/ n! z. W5 W6 w
    16.     <!-- 视图解析器 -->
        p' O4 u) h! B0 S% n- I9 w
    17.         <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">) E3 u! S4 z6 H) b6 S0 E
    18.                 <property name="prefix" value="/WEB-INF/jsp/" />
      9 o  \8 h5 |! \
    19.                 <property name="suffix" value=".jsp" />
      3 T# x8 y1 [: t2 d1 \
    20.         </bean>
      ' i7 ^  F6 U9 B/ g
    21.         
      ! o  R$ K0 ^# K7 E8 T) Q, l
    22.      <!-- 异常解析器 -->
      ) K; \9 |( ]2 Z) X! ~- [* h
    23.    <!--  <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
      7 c  z( [0 `4 ^* S1 l$ q
    24.         <property name="defaultErrorView" value="common/error" />
      + [4 K0 D$ I: M$ r* p& e$ H
    25.    </bean> -->
      0 @  }4 c4 U% @- [( w! x
    26.      2 d& \% m6 C' n% R
    27.      <!-- 拦截器  -->
      , A) K; p) R  ~8 h* S
    28.         <!-- <mvc:interceptors>0 n$ Q: G5 q3 H+ x2 ?4 S" j
    29.             <mvc:interceptor>
      ) K- [$ J" Y( {; b8 G2 V
    30.                <mvc:mapping path="/admin/*/*" />
      3 W1 k1 ?" }. m; k2 x2 {
    31.                <bean class="com.filter.CommonInterceptor"></bean>
      / l0 |+ X; S. Y+ S6 G. m
    32.             </mvc:interceptor>9 F; M3 ]+ T! R, y0 P
    33.         </mvc:interceptors> -->
      . r& s, }% a6 t' t, y9 E3 X: e

    34. & m2 J9 ]7 h6 v, x+ I. R
    35.         <!-- 上传文件相关的配置 -->! Y% x( c( G1 ^* |4 R
    36.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">2 s! @  u0 D. M+ e8 L2 p
    37.         <property name="defaultEncoding" value="utf-8" />2 f; h' q0 f0 Q; h3 o; k
    38.                 <property name="maxUploadSize" value="104857600" />
      8 C" k& w8 r% ^3 N+ h7 ]: x
    39.                 <property name="maxInMemorySize" value="4096" />1 u* y. v/ L8 U0 P# Z- J$ j( @& v7 Y5 @
    40.         </bean>- X" i5 v7 C/ }, \2 i% F
    41. </beans>
    复制代码

    " L6 b3 T+ I( a- h/ H% @) z! }- q, i% z

    * ^2 f" ]" D' E# p1 F8 BSpringMVC+hibernate4.3+Spring4.1整合案例

    8 }2 c. u1 e5 d( z% o9 v3 r; w
    / X; X2 i+ E  I0 h: k

    科帮网-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 |只看该作者
    " }: e9 p1 D5 x3 l
    下来,学习一下。谢谢
    回复

    使用道具 举报

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