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:
/ \# ^0 i+ r9 M* k' r2 ?, H8 T0 l- y# `1 t. M: L
- <?xml version="1.0" encoding="UTF-8"?> ( k3 D( Y1 V' ^1 ]
- <beans xmlns="http://www.springframework.org/schema/beans" ; z6 V3 f$ X" F3 g
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" : Q: i; r* M& t
- xmlns:p="http://www.springframework.org/schema/p"
# d$ j0 D, i: K& u9 g) e2 j - xmlns:aop="http://www.springframework.org/schema/aop"
. o- Y1 \/ ?4 q4 u# Y$ r - xmlns:context="http://www.springframework.org/schema/context"
5 f) l2 t# Z8 g* V- E5 S - xmlns:jee="http://www.springframework.org/schema/jee" + r7 H1 R7 q- C4 m9 I
- xmlns:tx="http://www.springframework.org/schema/tx"
7 o* H/ F+ B; \! A+ z0 b - xsi:schemaLocation="
8 ?1 z2 t( V( F& K/ U - http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
. P$ y1 x/ }# c' B9 F/ c - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
( t& U; B. O j/ a) X+ J! Y - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd 9 y! v8 v8 s# o. J+ ^3 q, m
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
+ x3 d6 E6 s8 _4 | - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> ; ?5 C. h4 l5 {) X
- ! i* Z: \2 Y$ P
- <!-- <mvc:annotation-driven /> -->: G' {; b' T$ V' h5 h% S9 o
- <!-- 【配置视图解析器】 --> 4 w3 _- @" b$ g% ]4 C) [2 t! Z1 d' B
- <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 --> 1 N& ]7 e/ J5 k; D2 }6 R0 X4 ^4 N
- <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 --> 9 X. X) g0 y0 m) v0 Q Z, x
- <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
3 ^- C. \8 |8 ~/ ?; Q# e* m( ? - <property name="prefix" value="/WEB-INF/jsp/"/> 1 Z! } h* m4 l
- <property name="suffix" value=".jsp"/>5 L- m+ ^+ w# q& t1 v3 G3 q3 F
- </bean> -->
4 V9 |3 M' D; ^7 K* G0 | q/ s { -
- Q/ _9 j0 d1 ~, A - <!-- 导入springMvc.xml配置文件 -->2 p% J* \; j0 {, M
- <import resource="classpath:config/spring-mvc.xml" />. x% w' g" H" j! @8 d! X
- <!-- 加载数据库配置 -->7 a3 b& P5 y/ g: ?! Y; L
- <context:property-placeholder location="classpath:config/db.properties" />
L' @% x- j+ u% ?4 z - <!-- 加载数据源 -->" a, A# T3 ^( B7 T; k7 l; ]* ~0 j
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">6 t7 u/ n& B+ a4 K; m! b7 x3 t
- <property name="driverClassName" value="${db.driverClassName}" />
' A& p" Q8 O- F5 r, Z; w5 o - <property name="url" value="${db.url}" />
% R- w& ^3 [& u: @ - <property name="username" value="${db.username}" />4 V$ B- n+ Y& e6 c0 m8 [* b. `- e
- <property name="password" value="${db.password}" />
+ n$ u4 ^4 z* D, }: Y5 b% I4 f! w - <property name="maxActive" value="${db.maxActive}" />- g4 a; W8 f) L l0 R
- <property name="maxIdle" value="${db.maxIdle}" />
0 D6 u9 A; g" p6 n; e! l - <property name="minIdle" value="${db.minIdle}" />, H ]4 U/ ]9 @% G2 o8 C6 @3 s( M
- <property name="maxWait" value="${db.maxWait}" />! J+ B$ ~( P% G/ ~+ R: Y8 U; \
- </bean>
: X1 s( z- l& f4 i! x% @4 \0 i -
( c# K1 i, w& G1 A# e4 T$ s - 0 a9 x: w E( Q
- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 1 Z8 v F/ G( z7 i z& n" J
- <property name="dataSource" ref="dataSource" /> + r3 a1 n* w2 d0 V! K
- <property name="mappingDirectoryLocations"> & Q9 i) i9 Y) j7 d5 j
- <list>+ f$ N& r2 I e
- <value>classpath:config/hbm/</value>2 C6 ^ x3 u. R
- </list>
, [6 _3 u% _2 ]3 m/ m! \$ q - </property>
5 p) V6 s2 k4 q) L* q* B - <property name="hibernateProperties"> ! J- H0 L% u. R3 W
- <props>
/ F4 E+ E5 h: [/ |) D - <prop key="hibernate.dialect">${hibernate.dialect}</prop>0 y1 ~- p+ X( ~) S [
- <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
0 i5 J- N5 o; i& C# j2 } - <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>4 r0 [& w' |, `0 A
- <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->
( {5 M. W! D, w4 a9 t - </props>
8 R% W4 F5 K X6 p - </property> $ E7 T# r: `/ v7 B
- </bean>
) c" _1 ~; a ~' Z -
) m0 U5 s. p% {9 M0 e; { - <!-- 声明式事务 --> 1 E0 T5 [. E0 B
- <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> : j/ G1 k2 i, Z4 @1 w+ l
- <property name="sessionFactory" ref="sessionFactory" />
' G9 ?+ ~$ Q* q" s+ L - </bean> 6 ?7 b) R( F% t" b+ e) a
- 4 s" q" |3 l6 c9 b! y) ^' A2 L' N
- <aop:config> ( N* f- e9 _; E
- <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />
5 I! |* E; A9 _8 i- p& T - <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
5 ?, M7 U6 e1 u# {7 r+ U - </aop:config> 6 e0 M0 q( ?- J" L/ i3 L" H ^
- ' `4 t; a4 Y7 P. C3 ^
- <tx:advice id="txAdvice" transaction-manager="transactionManager"> 3 E6 ]. m8 {, {2 M5 j3 A
- <tx:attributes>
) }7 n* N; z' j5 o7 x - <tx:method name="save*" propagation="REQUIRED" />
1 O5 {2 U2 P; x0 [! v) g) | - <tx:method name="add*" propagation="REQUIRED" />5 D* Y# f6 h9 {- ?" G- x) ~5 w
- <tx:method name="create*" propagation="REQUIRED" />
# e' `) t/ `4 Y7 w* ^! } - <tx:method name="insert*" propagation="REQUIRED" />
% D c' h0 m H& ]1 ~; h g. F - <tx:method name="update*" propagation="REQUIRED" />8 [* z) ]6 I) t0 W5 P, M
- <tx:method name="merge*" propagation="REQUIRED" />5 Z( r5 |! R$ N0 }" Y6 w+ c
- <tx:method name="del*" propagation="REQUIRED" />4 n1 u2 W# y0 L# j; C
- <tx:method name="remove*" propagation="REQUIRED" />) D. w& u6 h9 V: v7 X, v4 {, Y/ K& ?
- <tx:method name="put*" propagation="REQUIRED" />+ F b; [3 s2 i) H
- <tx:method name="*" propagation="SUPPORTS" read-only="true" />
+ |' H' K- a3 [2 E - </tx:attributes> ' P' l. N7 C1 _; I# e
- </tx:advice>
& ?2 c) H' W6 ] - </beans>
复制代码 spring-mvc.xml:6 U. |3 V a# F: ^ X' Y0 Z# z
# a* q$ W* n3 l1 r2 f$ I- <?xml version="1.0" encoding="UTF-8"?>
! ], Z* [: t. V - <beans xmlns="http://www.springframework.org/schema/beans"
7 S1 [ @1 l2 @# y - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"( ?: e/ M3 b; ?+ u
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
# I6 x6 W( V$ v9 `. X; i1 C4 i - xmlns:mvc="http://www.springframework.org/schema/mvc"$ e/ _! p+ e5 Y0 P$ S
- xsi:schemaLocation="http://www.springframework.org/schema/beans
3 r M& f5 X& e6 x6 |0 K; _8 N - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 1 d- h2 B5 g. x1 M) ~
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
7 Z& i4 w; z$ _- J8 l" l4 N - http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
# h! k2 _9 p# x0 V - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd! Y4 B( Z% [6 K
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
( V2 N# {& ?" l9 c* d- U - <!-- 自动扫描的包注解 -->7 ~$ h# Q7 Z7 l- r: o
- <context:component-scan base-package="com.hoodo.rci" />
$ b0 D3 {5 `. p' h/ D3 O - <!-- 自动注入 -->
R. Y+ O( K: `5 L# o+ ^- ?. V2 \ - <mvc:annotation-driven />5 f- w& t/ F2 N
- <!-- 视图解析器 -->1 C% a8 i) \& V, K6 \" U1 e
- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">- G6 }' }+ ~1 x, K( R
- <property name="prefix" value="/WEB-INF/jsp/" />
; |" Y' ^/ |6 X# R" \: _ - <property name="suffix" value=".jsp" />
$ R9 r( h, X* o7 P8 x P - </bean>
( v. r* V. F$ J* g% r - 6 m4 `& C& ^. o8 H% ?* d x1 e. C
- <!-- 异常解析器 -->& W7 R& q$ N$ t1 K3 `
- <!-- <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">& M: e0 `% P/ \0 J, b
- <property name="defaultErrorView" value="common/error" />
% W' w/ F# ^/ o* j - </bean> -->* f; I+ g+ n, [( v' f4 p; F
-
4 w* R# S6 r- r' r8 ?, y' h+ g - <!-- 拦截器 -->
0 K& h% C* `2 U8 U; y - <!-- <mvc:interceptors>$ F9 Z8 U+ M: x3 _
- <mvc:interceptor>0 \( o0 K } W) k7 K- c
- <mvc:mapping path="/admin/*/*" />$ @2 A2 J/ Q- x7 S! u2 p
- <bean class="com.filter.CommonInterceptor"></bean>& A% J; ] C. I* M' W+ C
- </mvc:interceptor>0 n% a* ^2 c7 ~; Y
- </mvc:interceptors> -->
' O% u0 @: y, w
! C. f, }! l7 |6 G8 [* A- <!-- 上传文件相关的配置 -->
- Y& C/ m8 P2 H6 F) O. D0 H* I* y - <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">0 \9 F7 e8 J+ h4 q, F7 [6 v7 t; W
- <property name="defaultEncoding" value="utf-8" />
) s x8 t1 J- D* `; K. N - <property name="maxUploadSize" value="104857600" />) Z7 s" |( O/ W, S" @+ h
- <property name="maxInMemorySize" value="4096" />
$ S" c3 d; I" a6 d$ p - </bean>
# i. [9 K/ l1 O5 h3 @0 ?* {0 E1 X - </beans>
复制代码
! X w" ~& C1 l3 F0 T: j; i8 Z! M/ g* F. {0 `
( N) ?. b) ?2 E, q2 z
SpringMVC+hibernate4.3+Spring4.1整合案例" @% n9 \3 t0 b
9 k/ a; p' Q; V7 b2 t |
|