TA的每日心情![](source/plugin/dsu_paulsign/img/emot/shuai.gif) | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
springMVC+hibernate4.3+Spring4.1整合案例spring.xml:6 |9 O+ q& r$ F7 u9 X' D2 u
* G4 g C: _! `: L2 j# U- <?xml version="1.0" encoding="UTF-8"?>
' C, V. j% q6 ~2 y - <beans xmlns="http://www.springframework.org/schema/beans" - {. G2 D9 q3 o( c x9 r
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" / N8 c! {" C9 U b+ n. O0 k8 s6 C
- xmlns:p="http://www.springframework.org/schema/p" , ?( _. B+ h% _* {9 x; B1 A' e
- xmlns:aop="http://www.springframework.org/schema/aop" 9 d$ m# e* a( R6 l3 K1 l5 m
- xmlns:context="http://www.springframework.org/schema/context"
5 K! S T5 w1 A - xmlns:jee="http://www.springframework.org/schema/jee" ) A6 o0 i* J ]$ ^! t/ H# s, E9 s
- xmlns:tx="http://www.springframework.org/schema/tx" 5 K) Y# u/ E- _* e, m! ^ F
- xsi:schemaLocation="
# y7 J, [3 ^* r$ B2 K - http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd / V% M# }; |4 \; `9 \3 M. h3 V" M |
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
3 R# e4 u( _/ ?6 y. T2 I- O& p - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd ! a w1 a# U* A, r2 O4 `
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd 8 S9 T O6 c8 \
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> & i/ q5 \7 f5 N! L9 t; K
- 7 b' ?2 b$ r2 R9 E' f
- <!-- <mvc:annotation-driven /> -->9 }* S7 m7 D/ d, {( e7 K
- <!-- 【配置视图解析器】 --> & Q5 p( H1 I h# A* h; I
- <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->
7 f' m }: z# o9 D: Q- n - <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 --> 0 i# g+ F+ }! b6 V+ z. J
- <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
4 p/ `7 [* |* q' }. k& f2 l0 P4 E - <property name="prefix" value="/WEB-INF/jsp/"/> ( Y- y" z3 P9 y4 J1 {" o9 i
- <property name="suffix" value=".jsp"/>
# `2 P1 S, S# P: O* J - </bean> -->
# `* Q- Y6 W' d -
& o+ ? n$ x( u0 s$ a- P! @ - <!-- 导入springMvc.xml配置文件 -->
( \1 m9 d. o$ v0 v/ i" k - <import resource="classpath:config/spring-mvc.xml" />
S" ^3 }% c" L& B0 R, ?4 | - <!-- 加载数据库配置 -->
# r2 @ E% C& u1 G, y2 a* ] - <context:property-placeholder location="classpath:config/db.properties" />
, d9 |' m/ t: }! W& P - <!-- 加载数据源 -->
; c& x. [+ {! b0 h9 Q - <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">; H* c, _( z N, \
- <property name="driverClassName" value="${db.driverClassName}" />
' D% \# Y# ?6 r1 F' d - <property name="url" value="${db.url}" />9 t7 I, C! N4 F% R4 ~
- <property name="username" value="${db.username}" />
* ~& O7 F% f9 I7 f - <property name="password" value="${db.password}" />- r& u: r: |! v, J# @. ~ H, e
- <property name="maxActive" value="${db.maxActive}" />
& ^. D, b/ d7 V7 } o - <property name="maxIdle" value="${db.maxIdle}" />0 [! v; A# k; H/ W9 m3 q' X! u/ F
- <property name="minIdle" value="${db.minIdle}" />9 N0 `% g# q' E% }* \' t6 C
- <property name="maxWait" value="${db.maxWait}" />
4 N/ M: O1 x2 m9 n! u$ D - </bean>. n5 [: N$ K& w; `$ P9 b; A: ]
-
8 a! O4 H8 v9 i& L -
; r0 u; R! L. O# W9 ]. K5 I% B - <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
! @( B9 I! B' d4 H6 X - <property name="dataSource" ref="dataSource" />
6 ^5 q; }* r+ d2 J0 a6 \7 ~& W' [ - <property name="mappingDirectoryLocations"> & [# ~ Y$ s6 {
- <list>5 t. j9 T9 n& Z9 }/ D R
- <value>classpath:config/hbm/</value>2 K7 I/ q" p7 Z2 ~
- </list>. Y1 m/ |" E" r0 f: v
- </property>
9 l* e7 s+ `- b) {, {) j( | - <property name="hibernateProperties"> 1 Z: P, C# w( V
- <props>) w0 @7 P C" [
- <prop key="hibernate.dialect">${hibernate.dialect}</prop>$ x2 O4 L9 m: I: Z6 @
- <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>2 w0 u1 K$ d7 U* M8 ^
- <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
4 S, u, W( o# r, q - <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->
2 x* X) U# T4 x2 X) S. e2 A - </props>
! n' e5 ?# I8 g9 ` - </property>
A1 {: n- S( _6 V' s - </bean>
6 E4 ?* u8 `, d9 k9 O+ \. E - 8 i' O0 V+ H6 l5 \2 \5 j
- <!-- 声明式事务 --> 8 i4 L* ^, J9 G# K# e5 K
- <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> : M! p. U. J# K$ d7 _7 i# @
- <property name="sessionFactory" ref="sessionFactory" /> ( @# a. Q3 j' E! ?
- </bean> & I/ g6 ]2 h, K0 Y! |2 v6 y
- * A' L& |, t! }' P( M5 V7 y; D
- <aop:config> & u$ J3 P! o- a+ x( k4 n. m
- <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />
7 M4 z3 X+ r7 T3 K! a - <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
2 p. K r# d/ b- C - </aop:config> ) Q% {" ~8 E; O0 P5 h% S- x
- / l) ?: o5 S1 U3 Z* c! R
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
. o B) Q% E( h c( ^ - <tx:attributes>
) K+ s4 v7 M; \- g$ e9 l - <tx:method name="save*" propagation="REQUIRED" />4 k% Z; `8 A, B9 }1 g& \: K
- <tx:method name="add*" propagation="REQUIRED" />
4 k0 `; t) o8 \: Y; B6 O0 Q! x+ L - <tx:method name="create*" propagation="REQUIRED" />
: E9 }8 q1 m2 W. Y% w - <tx:method name="insert*" propagation="REQUIRED" />
6 J: n, v8 }% e - <tx:method name="update*" propagation="REQUIRED" />
! j m! S1 u, { - <tx:method name="merge*" propagation="REQUIRED" />
8 @- o6 n( _, p' V' t9 f - <tx:method name="del*" propagation="REQUIRED" />
3 j: D! E( H& b8 C( ]! I - <tx:method name="remove*" propagation="REQUIRED" />$ g4 s1 T2 d" p7 e# E. K+ {4 A3 a8 m
- <tx:method name="put*" propagation="REQUIRED" />: }' {! k& V7 m! i
- <tx:method name="*" propagation="SUPPORTS" read-only="true" />
; X. ^0 K' X* C+ b - </tx:attributes> 4 s8 O3 `+ z5 L% j3 M
- </tx:advice> - w# W) e' }. U3 s0 ~
- </beans>
复制代码 spring-mvc.xml:0 e+ M6 p# G3 f& B1 r
5 ]3 {1 k, w+ P' x% S4 [- <?xml version="1.0" encoding="UTF-8"?>7 f% c1 r! h: b# y9 Y$ }) F" B
- <beans xmlns="http://www.springframework.org/schema/beans"
& D" B+ x% C; W% _ - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
; x, g* @# |! ^, i) v# O2 a! L - xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"" p T3 b; U- B6 \( a/ v* I" P0 l) n) ^
- xmlns:mvc="http://www.springframework.org/schema/mvc"
Q6 }! Z% J4 Y# l - xsi:schemaLocation="http://www.springframework.org/schema/beans " w3 ~% h: |' B; Z8 O
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ( Q: g L) l/ I8 ]+ n
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd 4 [, ~: ]" ?; P d6 K/ o
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd ) c: U- G; ~; y& W" D; B* v2 F
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd6 k+ x9 c) F+ m. }- b/ X/ t
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
$ O7 c2 q3 @+ C6 `" B - <!-- 自动扫描的包注解 -->
) ?1 C5 \6 p# g' v! J& y( S0 s - <context:component-scan base-package="com.hoodo.rci" />4 a; Q, }: C1 c+ m7 |- y
- <!-- 自动注入 -->
# e% ^9 m* ~7 a0 x: P3 N - <mvc:annotation-driven />
( Z) w9 h. _1 D" c" N& v - <!-- 视图解析器 -->
7 n5 ?8 ~) ~: a6 L5 `& O: B( d - <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
( T. G7 a# V3 T5 ]% o - <property name="prefix" value="/WEB-INF/jsp/" />2 s6 o+ l# a6 J2 m. W5 m( l7 q. U
- <property name="suffix" value=".jsp" />
. \5 {) i$ H* ^# O& V - </bean>4 H$ |% |3 T0 Y: ~9 Y! g
-
5 c& X4 D% Q7 J" T/ Q1 \- [ - <!-- 异常解析器 -->0 m- i$ l& a2 ^: z; ^
- <!-- <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
6 I0 Y: f8 R- ~2 S! [7 R - <property name="defaultErrorView" value="common/error" />
0 W, j- |5 E' e; j8 s }- c - </bean> -->1 v9 q' x N' i( X
- 5 b. a; C! O4 w: H
- <!-- 拦截器 -->
; V$ N) P: L( j2 R* `: X - <!-- <mvc:interceptors>$ C/ S) r: z$ z: d9 d; Z: C
- <mvc:interceptor>3 u3 S( P6 V# J$ V
- <mvc:mapping path="/admin/*/*" />- ?8 S1 _5 W% Y. J2 n5 H
- <bean class="com.filter.CommonInterceptor"></bean>
c9 }$ f! V& U- V' X - </mvc:interceptor># o# u: A5 N4 o
- </mvc:interceptors> -->) W! q8 i( O: d7 [7 w T
2 n& S$ t4 @8 P# P1 D- <!-- 上传文件相关的配置 -->9 ?/ \8 e1 O) ^5 j4 l, }, @
- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
3 }' h3 a2 m3 k; F, X, ^ - <property name="defaultEncoding" value="utf-8" />
) I. u; U1 L" _# i G6 c$ t - <property name="maxUploadSize" value="104857600" />
2 M2 L4 [" }, @& M! }6 a - <property name="maxInMemorySize" value="4096" />
+ x1 r- b @) g+ V" \ - </bean>/ y8 F' ?& V. B! I
- </beans>
复制代码
- p: {6 t0 _# s( k8 D; U5 e9 Y$ s7 N2 m
: q5 ]8 s0 d% u, ~SpringMVC+hibernate4.3+Spring4.1整合案例
# L* _/ m: s X5 l- r; U V2 m. I! a& p
|
|