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:5 V* p1 w* M, t) B% d$ W$ f
3 x& H8 z7 n) G2 A4 M3 X- <?xml version="1.0" encoding="UTF-8"?> ; _, X9 U- S9 ^( `, w
- <beans xmlns="http://www.springframework.org/schema/beans"
) E7 k+ R& }" [1 `. O) N/ ^: r8 O0 @ - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 i/ o8 ?' X, W. f# r
- xmlns:p="http://www.springframework.org/schema/p"
. b+ c" a7 ]- V* u e" @+ k - xmlns:aop="http://www.springframework.org/schema/aop" : F/ Y: a& {) C2 t- u5 i$ g' K5 Q u2 ~: l
- xmlns:context="http://www.springframework.org/schema/context" ; i# s$ |- J+ x1 s* b' f; N
- xmlns:jee="http://www.springframework.org/schema/jee" 7 {. Z6 k% X& u/ b: F
- xmlns:tx="http://www.springframework.org/schema/tx"
~4 u+ n, i1 M) c - xsi:schemaLocation=" ! @- S2 L, s2 {# J b" r, e8 J
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
$ [ R b8 `, {3 p( m - 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
- 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 - http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
; h) t7 x& N, z$ m% j - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
! ?4 w5 ^6 q. v0 m& `" P - 6 M4 C) u3 E7 G# g6 O7 W- R
- <!-- <mvc:annotation-driven /> -->
$ c$ w- I# X1 N. t - <!-- 【配置视图解析器】 --> 3 M3 k5 Q2 Z- z' [! X; t) W! ~
- <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->
f9 h1 D7 c. I1 I - <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 --> / Z6 R3 y, Z! e9 d
- <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- U* U8 f* v2 ?+ ? - <property name="prefix" value="/WEB-INF/jsp/"/>
$ S0 f/ B1 A: @ - <property name="suffix" value=".jsp"/># g: R T) J6 I' ^
- </bean> -->2 V0 J6 H# y; U
- 9 L% ]: G2 m/ P0 h# Q* z
- <!-- 导入springMvc.xml配置文件 -->2 h) E8 _9 A i% @. c
- <import resource="classpath:config/spring-mvc.xml" />3 C, R( ^! ^$ R! f+ q% T( @
- <!-- 加载数据库配置 -->3 [1 x+ s& [' R
- <context:property-placeholder location="classpath:config/db.properties" />
/ V0 Z- {) k" t, b( ~ - <!-- 加载数据源 -->5 X' m4 y+ [0 r- s
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
) @& u! x# U* W/ B - <property name="driverClassName" value="${db.driverClassName}" />) p1 _1 u+ S) S+ \
- <property name="url" value="${db.url}" />
5 s+ N% z0 t q K - <property name="username" value="${db.username}" />
+ |, H1 |' |2 ]3 U" x0 U5 a - <property name="password" value="${db.password}" />+ @" b% ?! J5 F: ?& Z
- <property name="maxActive" value="${db.maxActive}" />, [0 e! L. p% X; T
- <property name="maxIdle" value="${db.maxIdle}" />5 f T7 d: g2 a3 @1 B
- <property name="minIdle" value="${db.minIdle}" />' ^& q5 U& {" @+ W5 G5 z3 g
- <property name="maxWait" value="${db.maxWait}" />- E: l8 m+ z0 G1 e- \
- </bean>
9 C$ Q& Q6 W+ X# e - 0 _$ H: T6 f4 U( \
-
, `0 ?+ C6 V/ x/ {! Y9 v3 j' } - <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
- p, K4 a* J: u4 H5 M - <property name="dataSource" ref="dataSource" /> % L+ f/ ]4 w2 G7 l* O
- <property name="mappingDirectoryLocations">
Q% U- o1 p6 H" k; x6 l/ D0 w - <list>+ b" p _8 _3 W' W- I! y0 P7 v
- <value>classpath:config/hbm/</value>
- j$ w) s! n+ L1 q# f% Z1 N - </list>2 b9 R. o7 w7 X* |+ e n
- </property> ) o2 O4 h# M/ p: Y# h3 d
- <property name="hibernateProperties"> 8 f# W/ X, f, a9 Z' D6 j7 ?' r
- <props>$ E5 h$ [. `8 n2 Z2 ^
- <prop key="hibernate.dialect">${hibernate.dialect}</prop>
8 q y% l o0 \4 q - <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>/ M' _$ U5 ^4 {. f- r7 ~
- <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
9 Y2 b1 l) R5 R$ S3 C6 n - <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->& ^8 p* m2 R5 B% r( c
- </props> 5 _9 ^8 ]$ f( \5 b4 l) E+ _5 R. o
- </property>
/ n/ n7 {: t! Z5 Q - </bean>, V. i4 ^: h4 F1 V) ]
- 3 g* A+ y* i' L9 G0 b- n: Y
- <!-- 声明式事务 -->
$ F7 f" [% t2 ~$ l( v - <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 4 ^0 W5 M* Q: r+ C
- <property name="sessionFactory" ref="sessionFactory" />
1 n" f3 D2 q# k! S( _3 x, f e4 Y - </bean> * N; r R- s5 b# V. {* n' \0 R
-
; D$ q; B/ @& M! y* X$ J - <aop:config>
0 s; t7 J& O$ Z+ u3 s, z - <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" /> ! p# z1 K- ^7 N$ \# ^
- <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" /> 0 O4 N8 H4 G- J) H/ F4 W3 _- k
- </aop:config> 8 d+ S6 c& Q& H2 m
-
9 e& R( M* I. T! E5 x2 B8 S - <tx:advice id="txAdvice" transaction-manager="transactionManager">
, Z- `. } c: L. g6 P& [ - <tx:attributes>
- ]8 j8 T& B* a2 P - <tx:method name="save*" propagation="REQUIRED" />, d# X( h! g0 z" a! s
- <tx:method name="add*" propagation="REQUIRED" />" ]1 p$ }3 H6 m( q6 Z: P4 x& W
- <tx:method name="create*" propagation="REQUIRED" />
+ G, n; p: N, t+ ~+ b; h+ H% |7 g - <tx:method name="insert*" propagation="REQUIRED" />
4 O9 ~; ]# B, T1 ` - <tx:method name="update*" propagation="REQUIRED" />" a+ S5 x$ | Z( `2 h6 V# L
- <tx:method name="merge*" propagation="REQUIRED" />
8 p' r! j. n9 v3 J6 R - <tx:method name="del*" propagation="REQUIRED" />) f* e1 M+ J. R& ]
- <tx:method name="remove*" propagation="REQUIRED" />: S9 L! ~, e2 F/ F" I
- <tx:method name="put*" propagation="REQUIRED" />5 J9 o, Z! ~) h; i
- <tx:method name="*" propagation="SUPPORTS" read-only="true" /> 3 e4 q6 x3 B0 n F* [
- </tx:attributes> 5 G! p% w1 J, E7 c
- </tx:advice> # {1 t! L4 E' G2 {0 |/ c
- </beans>
复制代码 spring-mvc.xml:5 _7 ~7 b% f. W
?& q8 J; {, e4 u9 T; }9 d- <?xml version="1.0" encoding="UTF-8"?>
6 x; W- t. ]: ~9 b& Z9 v$ K9 A& ~ - <beans xmlns="http://www.springframework.org/schema/beans"
2 N" F1 T5 ^: z$ s4 g - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
1 j& {3 H. ^( e R - 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 - xmlns:mvc="http://www.springframework.org/schema/mvc"
9 }2 J; K( L" e" L2 S7 C6 S - xsi:schemaLocation="http://www.springframework.org/schema/beans 1 X8 ?1 s. C5 r
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 2 z: I+ _0 }2 k( x7 g0 J" M
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
. W3 y; [; [1 D8 n* D6 F - 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 - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
9 }# `6 a( O0 T: L - 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
- <!-- 自动扫描的包注解 -->
; P( l5 L9 E6 G. c5 j+ Y - <context:component-scan base-package="com.hoodo.rci" />
2 O" l7 k: k. C2 u2 u; m% F. M - <!-- 自动注入 -->
- ^6 D0 x# g/ t, A X+ G. s! ?5 P - <mvc:annotation-driven />
2 @* [$ i7 n* _7 T7 {0 C' k4 Z - <!-- 视图解析器 -->1 c" S7 Y% R5 m; S' p
- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
" F2 Q/ a/ l/ B - <property name="prefix" value="/WEB-INF/jsp/" />
& H1 ~4 y0 U0 k% Q; R- `+ V - <property name="suffix" value=".jsp" />
& k- j1 x/ I" O: O* M% \ D - </bean>
9 U$ H8 u( a; _) _7 p" q+ U& m - / L- L6 Q- m+ X! i8 u( g
- <!-- 异常解析器 -->
( n/ r3 G3 j' |9 U: ], H; N - <!-- <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
! Q3 \* u) g' p q. `) t$ E - <property name="defaultErrorView" value="common/error" />
" n+ t, [6 D7 l4 l2 \9 f7 ?4 i$ X! I - </bean> -->
' \8 }8 ~& ^8 F+ {$ e( Z -
, i$ O* U' e8 b$ g - <!-- 拦截器 -->
# N! @- ~+ ?2 d' a% l! h- x0 K - <!-- <mvc:interceptors>
# p5 a4 q2 D; [3 z) D) }. M/ s$ I5 { - <mvc:interceptor> r" [3 C0 d* q; `1 u3 O- m
- <mvc:mapping path="/admin/*/*" />
/ d& K0 f1 b' [& ]. c+ _ - <bean class="com.filter.CommonInterceptor"></bean>& N* o, ]% k( x4 {. r' }$ h6 `
- </mvc:interceptor>
% H# S+ ], X$ b' s - </mvc:interceptors> -->
% w% N+ E6 O; s2 F3 k$ o' i7 P
# O2 _5 |3 a" _" N- <!-- 上传文件相关的配置 -->$ u" r& i) N7 ?! s4 d! N
- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
8 \6 g# A; g2 N1 G - <property name="defaultEncoding" value="utf-8" />
6 S% [5 j4 S. r3 _2 {. V - <property name="maxUploadSize" value="104857600" />5 {0 w8 F4 g9 q% ?% n: k5 L
- <property name="maxInMemorySize" value="4096" />
7 D# r. `" f. \1 a1 }: k% v - </bean>( x; b1 A; e% q3 e; n
- </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
|
|