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:7 \- D/ ~9 {7 r8 K" F
/ H4 _0 J* k2 {" @; h5 I- <?xml version="1.0" encoding="UTF-8"?> : A0 R% a) o6 |3 v8 F! A1 z
- <beans xmlns="http://www.springframework.org/schema/beans" / ]: Z, I6 I2 d. D6 W- d
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ( M' M, e/ W- x1 n7 o
- xmlns:p="http://www.springframework.org/schema/p" 8 n* z0 Y" ]1 ?( U% y/ e
- xmlns:aop="http://www.springframework.org/schema/aop" - J3 p, n* C/ I8 t% d
- xmlns:context="http://www.springframework.org/schema/context"
0 L r$ ~( z: n Z5 j - xmlns:jee="http://www.springframework.org/schema/jee"
! }6 s) a+ M3 Q - xmlns:tx="http://www.springframework.org/schema/tx"
\0 R' T) O" i- a - xsi:schemaLocation="
+ L V: ~6 ~% c- C9 u& @5 A( c; b - http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
( r" R$ Q3 c* j - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd / R" \5 M/ z; ]. V, U# h
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd % o$ ^% R i* d+ Q, Q
- 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 - 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
- ; s+ n4 U: V" z8 G* n6 N8 v
- <!-- <mvc:annotation-driven /> -->
& \2 d* q- @8 b" I7 O; U - <!-- 【配置视图解析器】 --> 2 m r8 s, G5 q
- <!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->
" w1 t/ k& x* M+ F0 \% u$ b - <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 --> $ h% N. |7 q7 o+ R* C9 I$ r2 D
- <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
8 R7 M$ E* `8 d - <property name="prefix" value="/WEB-INF/jsp/"/> ( e- B$ F. P9 s/ O: K- n
- <property name="suffix" value=".jsp"/>, X& Z" r: u4 m s
- </bean> -->
7 I1 I9 r3 e+ I& V - 8 X1 x' p2 C/ m( y" S! @
- <!-- 导入springMvc.xml配置文件 -->
- a8 f% E5 x1 ]0 e; B6 J0 M2 Q" z - <import resource="classpath:config/spring-mvc.xml" />
/ @2 T v4 {5 K9 q- k - <!-- 加载数据库配置 -->2 O. n$ o# O& \) }
- <context:property-placeholder location="classpath:config/db.properties" />
8 w" _! ^% `. `) u) ?$ ? - <!-- 加载数据源 -->: O6 A" ]* |& S: `7 G
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
8 }. q+ t+ O: Q$ V - <property name="driverClassName" value="${db.driverClassName}" />1 X$ ^6 B3 L# O* Y- e
- <property name="url" value="${db.url}" />. w, U; S# ]$ g. c \5 y: S0 F
- <property name="username" value="${db.username}" />
( m7 w5 b) }9 L" U9 s - <property name="password" value="${db.password}" />0 [9 ~- o; r+ t% ]% d! l/ o# d
- <property name="maxActive" value="${db.maxActive}" />
* n5 D0 s' h o: G- s4 `3 O5 \ - <property name="maxIdle" value="${db.maxIdle}" />
8 V0 T4 _: w+ B+ T) r - <property name="minIdle" value="${db.minIdle}" />9 E- u7 B: K9 U! }2 D- I
- <property name="maxWait" value="${db.maxWait}" />
5 @: K2 b) T: H - </bean>
) }, M3 m. }9 B/ a) u - E5 p& m* t: V& X: F% o- O% f: w
- {: @6 V- Q% _
- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
1 I' G1 u+ Z+ p) I0 m - <property name="dataSource" ref="dataSource" /> 9 a! |' R; D, L
- <property name="mappingDirectoryLocations"> 9 i" v, s6 Y" Q b+ I
- <list>
# R5 \* z+ c8 u7 S7 v2 X& Q6 L - <value>classpath:config/hbm/</value>
. g6 V5 o: J5 c - </list>2 N( Q6 k4 B+ C
- </property>
5 e h3 u# P& b' S7 r9 n$ J N - <property name="hibernateProperties">
, n3 {# v+ [2 F& _ s/ L - <props>& q* ^9 {4 a0 e3 j. P
- <prop key="hibernate.dialect">${hibernate.dialect}</prop>
+ C) Z' G# _8 Z- N l9 i - <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
4 p K$ P6 v3 }$ _# U- l9 Y( } - <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> g1 x0 d0 W$ S
- <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->
7 ~" o2 ~9 g D3 D" x: K/ t3 B - </props>
- d( ^+ D4 x9 u5 p- ]# Q8 y - </property>
! ]6 `1 K5 q @ - </bean>+ u) k# u4 ?/ U3 \, M
-
$ d" q t9 R; g - <!-- 声明式事务 --> ( z; x/ I) T4 m. ~! K
- <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> ( i2 S1 w0 x- T- ^; n- W
- <property name="sessionFactory" ref="sessionFactory" />
( s: j' p; I$ I - </bean> * ^& W3 z9 e+ s2 T; t7 l2 c
- - J: U/ C: y- t1 H$ P! r4 C0 B4 G
- <aop:config> . ^ d7 v: j [3 l/ k( M6 E
- <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" />
2 p( F/ h5 h3 _ - <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" /> 3 d& Z& n- ]& D; X6 O
- </aop:config> * `8 Z0 p( k) e- g2 M) B
- 5 k% s- f+ Q& ~: M& O7 f
- <tx:advice id="txAdvice" transaction-manager="transactionManager"> " \6 ?# b5 N5 c
- <tx:attributes>
4 h* u9 C0 W( O" [& k2 H1 s# Y) R - <tx:method name="save*" propagation="REQUIRED" />" B: m) s# y$ z) E- W% b
- <tx:method name="add*" propagation="REQUIRED" />& J) }& O+ H& p( R& L
- <tx:method name="create*" propagation="REQUIRED" />
" Y1 A2 P$ b2 c& c& L - <tx:method name="insert*" propagation="REQUIRED" />6 l3 l7 I, h* x) I* }; e0 f# E
- <tx:method name="update*" propagation="REQUIRED" />! B! Z/ b0 i: w) G7 X6 ?
- <tx:method name="merge*" propagation="REQUIRED" />
$ a; ~7 t& b* j$ S( [9 z" { - <tx:method name="del*" propagation="REQUIRED" />
( s5 x4 L" `$ d - <tx:method name="remove*" propagation="REQUIRED" />
2 H2 h6 i2 K6 }& F - <tx:method name="put*" propagation="REQUIRED" />
7 l% v" o2 E0 R; `. A0 f - <tx:method name="*" propagation="SUPPORTS" read-only="true" />
. D& f: K# l" H; e* @+ ^' l - </tx:attributes>
: }/ _, D2 v' K/ R2 L' d - </tx:advice> + m1 _" t! J' D0 U$ O& D
- </beans>
复制代码 spring-mvc.xml:$ f. |$ f& e+ R6 M1 F
) E; F9 Y* Q5 Z- <?xml version="1.0" encoding="UTF-8"?>
! w# A7 o# c+ ]3 a4 N - <beans xmlns="http://www.springframework.org/schema/beans"! D5 o! x- \) D0 S: R3 f. R [2 ?
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
; W9 {0 `' E7 S! t9 [ - xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"( p d7 H6 @4 L j: g5 E- ]
- xmlns:mvc="http://www.springframework.org/schema/mvc"
}1 |/ t4 T9 S6 x+ d/ A# h - xsi:schemaLocation="http://www.springframework.org/schema/beans 3 `. u O m5 ~! B9 b
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd / J4 y$ E @& X+ b! K) V- A' D# H
- 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* |
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd ' ?7 u; e+ S4 }
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" A! |* ~+ G/ [3 t
- 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 - <!-- 自动扫描的包注解 -->' t" ^! z6 D5 ~! V! d
- <context:component-scan base-package="com.hoodo.rci" /> {! f6 c, |" @6 W( P+ ^
- <!-- 自动注入 -->2 ~6 e8 m v) g: o# f9 X" A
- <mvc:annotation-driven />
4 ^! ?4 N3 n: A6 G' c$ a/ n! z. W5 W6 w - <!-- 视图解析器 -->
p' O4 u) h! B0 S% n- I9 w - <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">) E3 u! S4 z6 H) b6 S0 E
- <property name="prefix" value="/WEB-INF/jsp/" />
9 o \8 h5 |! \ - <property name="suffix" value=".jsp" />
3 T# x8 y1 [: t2 d1 \ - </bean>
' i7 ^ F6 U9 B/ g -
! o R$ K0 ^# K7 E8 T) Q, l - <!-- 异常解析器 -->
) K; \9 |( ]2 Z) X! ~- [* h - <!-- <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
7 c z( [0 `4 ^* S1 l$ q - <property name="defaultErrorView" value="common/error" />
+ [4 K0 D$ I: M$ r* p& e$ H - </bean> -->
0 @ }4 c4 U% @- [( w! x - 2 d& \% m6 C' n% R
- <!-- 拦截器 -->
, A) K; p) R ~8 h* S - <!-- <mvc:interceptors>0 n$ Q: G5 q3 H+ x2 ?4 S" j
- <mvc:interceptor>
) K- [$ J" Y( {; b8 G2 V - <mvc:mapping path="/admin/*/*" />
3 W1 k1 ?" }. m; k2 x2 { - <bean class="com.filter.CommonInterceptor"></bean>
/ l0 |+ X; S. Y+ S6 G. m - </mvc:interceptor>9 F; M3 ]+ T! R, y0 P
- </mvc:interceptors> -->
. r& s, }% a6 t' t, y9 E3 X: e
& m2 J9 ]7 h6 v, x+ I. R- <!-- 上传文件相关的配置 -->! Y% x( c( G1 ^* |4 R
- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">2 s! @ u0 D. M+ e8 L2 p
- <property name="defaultEncoding" value="utf-8" />2 f; h' q0 f0 Q; h3 o; k
- <property name="maxUploadSize" value="104857600" />
8 C" k& w8 r% ^3 N+ h7 ]: x - <property name="maxInMemorySize" value="4096" />1 u* y. v/ L8 U0 P# Z- J$ j( @& v7 Y5 @
- </bean>- X" i5 v7 C/ }, \2 i% F
- </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 |
|