TA的每日心情 衰 2021-2-2 11:21
签到天数: 36 天
[LV.5]常住居民I
spring MVC+hibernate 4.3+Spring4.1整合案例spring.xml:6 c8 t4 V9 G% _& P% x* X# H
Q( u- q& D& Q0 {
<?xml version="1.0" encoding="UTF-8"?>
% l$ F+ z! b; [6 L( L C <beans xmlns="http://www.springframework.org/schema/beans" ) V3 X% N O6 c \& V) a6 m ?
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 Q1 |/ D% k$ k: \1 T* K5 J9 S
xmlns:p="http://www.springframework.org/schema/p"
2 B1 @3 z; `4 i5 H# L xmlns:aop="http://www.springframework.org/schema/aop" / P! G- v! g: H0 U" f
xmlns:context="http://www.springframework.org/schema/context"
1 c2 w, @0 I G8 A xmlns:jee="http://www.springframework.org/schema/jee" " C" f- @; G9 Q6 Z$ ^( X
xmlns:tx="http://www.springframework.org/schema/tx" + f5 m" y! j4 ]6 G: [
xsi:schemaLocation=" ' v' \; o; B! B, k- g5 J/ ~
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd + N6 L4 r; C& H' J; J0 h
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
+ }% V( ^2 M7 j H http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd 9 X" y. N2 A* Y
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd / g& W# {9 @$ P# c& S% D% K) P2 [
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> 1 \ B |1 y# d$ ~
. @8 L. W+ e |, R0 I5 a <!-- <mvc:annotation-driven /> -->
3 D1 P3 F* }$ r7 W' b2 q <!-- 【配置视图解析器】 --> & X5 h/ r0 x. U. J
<!-- InternalResourceViewResolver会在ModelAndView返回的视图名前加上prefix指定的前缀,再在最后加上suffix指定的后缀 -->
1 C- q* I( q7 W9 c8 D* \5 v3 E2 f <!-- 由于UserController返回的ModelAndView中的视图名是userlist,故该视图解析器将在/WEB-INF/jsp/userlist.jsp处查找视图 -->
7 R( }- s+ f; q' C$ B <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
5 F* ?; `: |5 V# P <property name="prefix" value="/WEB-INF/jsp/"/>
. p( e2 @ v9 _. l3 R <property name="suffix" value=".jsp"/>4 r2 z( K! p: R" K0 `- t8 V
</bean> -->
" u; p% }3 _' o9 p0 t$ w* O
* C$ b7 n, d1 R1 x+ l/ V <!-- 导入springMvc.xml配置文件 -->
% v/ v" f! T3 @$ n <import resource="classpath:config/spring-mvc.xml" />* X, K' ?) v2 s1 m
<!-- 加载数据库配置 -->
" C$ I0 r" t5 b$ l. B& h% j& Y <context:property-placeholder location="classpath:config/db.properties" />
6 `" [- L7 v8 A0 | <!-- 加载数据源 -->9 a; L9 M/ Y) `8 z* H
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">% _/ `( r" `& s+ b4 J# F: Y
<property name="driverClassName" value="${db.driverClassName}" />$ e* u; a2 W1 a$ L2 U) x
<property name="url" value="${db.url}" />
: a+ |; B) \; E: S <property name="username" value="${db.username}" />
; `6 q! n/ d* p) f! M <property name="password" value="${db.password}" />" l% l1 D. U. T- H0 j
<property name="maxActive" value="${db.maxActive}" />( l- t7 X/ y$ @# c# n
<property name="maxIdle" value="${db.maxIdle}" />! `! _+ N4 O/ n# p( n* F
<property name="minIdle" value="${db.minIdle}" />7 U6 s& L: q# K$ K( d$ U
<property name="maxWait" value="${db.maxWait}" />! K/ A& Z0 h( K
</bean>
& c" {/ R4 D4 _6 ]6 J( d
# s7 L+ |5 x' P
' j3 l: v. B/ j( Y* B3 a <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> $ k! Q1 n( [+ W, \! ?
<property name="dataSource" ref="dataSource" /> % d! @# h4 M$ L1 U& @! |+ B. @+ p
<property name="mappingDirectoryLocations"> 9 k0 b5 z9 H( B9 u( I( p3 H# r
<list>
C1 |: W% d( i4 ]2 i/ _3 m* C <value>classpath:config/hbm/</value>
! O# `# A1 | K+ A$ N) c7 [3 _! s </list>1 e& `% M) |) P& U5 l" n
</property>
{( s) A6 h2 K: F1 c <property name="hibernateProperties">
$ |, ^" M5 _ Z5 v" N <props>5 o3 g P5 k* p, c% h& M
<prop key="hibernate.dialect">${hibernate.dialect}</prop>, W5 ^ V& B- Y* U0 T
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
0 S3 c1 Y# d i/ o' b2 F <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
! [0 n# [9 b" ^4 c <!--<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>-->" n# I6 m. \3 }7 _, l4 w" h( j
</props>
! N9 V4 a/ K* w- ^3 B a </property>
% q3 A- S: J# e9 o4 l/ _ </bean>; {8 ^( [2 E" N* q) M+ o0 R
2 G! K4 D" ?" a$ b4 q; g; L <!-- 声明式事务 -->
. H1 c% h# ] u! i/ P9 b! k; Y6 T7 |! ] <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
; A, Y, ~6 f$ }+ e/ N: f <property name="sessionFactory" ref="sessionFactory" /> 6 D/ g& G, E I. X
</bean> ( G5 z& {( G- h6 v: O
% i: i V: i' ^5 J <aop:config>
: e) ?/ _- z2 L ` <aop:pointcut id="productServiceMethods" expression="execution(* com.service..*.*(..))" /> ' e& y) f8 h0 a; E
<aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
* g C }& W, ^0 E+ q* | </aop:config> + W) ~8 B& v! q8 \, W
n6 D# h6 A# ^2 B5 T
<tx:advice id="txAdvice" transaction-manager="transactionManager">
( [4 i) K& D8 R4 |& A <tx:attributes>
8 k) k) U; V3 c( @4 D1 l <tx:method name="save*" propagation="REQUIRED" />
% B7 V; Z1 ~8 k3 e0 Z, Z <tx:method name="add*" propagation="REQUIRED" />
: s' c# w; A. U/ ]" Q6 F) N <tx:method name="create*" propagation="REQUIRED" />& b5 K$ [0 q! @1 G0 I
<tx:method name="insert*" propagation="REQUIRED" />
5 }$ M9 A+ ^7 {* G: y s. l <tx:method name="update*" propagation="REQUIRED" />' ]" a, G, ^+ H9 [, p( F8 R. Y
<tx:method name="merge*" propagation="REQUIRED" />) b6 h2 P. c2 |7 q2 e8 J* n
<tx:method name="del*" propagation="REQUIRED" />. k0 @5 `$ K0 b9 \* d4 _, x3 A
<tx:method name="remove*" propagation="REQUIRED" /> L7 z+ G9 ~$ b$ J6 }% w- x
<tx:method name="put*" propagation="REQUIRED" />
8 l7 k: l/ C, g" w <tx:method name="*" propagation="SUPPORTS" read-only="true" />
. x% Y+ U, d: t* W( @ </tx:attributes> ) K2 D( U& A1 T/ Y5 z& `' f' o7 o I
</tx:advice> # |5 g- N5 J6 {- j5 S
</beans> 复制代码 spring-mvc.xml:
3 [! E" M9 j) t9 r' S; A, ]; ]6 ]
2 T7 Z5 [* Q* C- D. P <?xml version="1.0" encoding="UTF-8"?>
: ?$ c( n- ~2 Z9 o <beans xmlns="http://www.springframework.org/schema/beans"
7 M5 l( m* U8 @' O xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"7 |# w3 R& J1 x) c8 S
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"0 \4 B- m9 y8 q1 p& h
xmlns:mvc="http://www.springframework.org/schema/mvc": h; H! ~: k1 U% t4 R0 q- C. u, R
xsi:schemaLocation="http://www.springframework.org/schema/beans
0 M' n7 T( [' K: R* A8 W http://www.springframework.org/schema/beans/spring-beans-3.0.xsd / ]/ c" Y/ J5 k5 Y& D! |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd 2 S& r1 ~2 `0 ]( R6 F
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd / Y4 f6 L" ^6 N: u, q, M
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
3 p9 M& M2 W; f. ^4 t5 X& z9 G9 J( R http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
' Q( g) w) B& ?1 t4 y1 I <!-- 自动扫描的包注解 -->
- I- R, G: ^/ z <context:component-scan base-package="com.hoodo.rci" />+ G/ _, P+ |, f* s4 h
<!-- 自动注入 -->
& g1 e" D: d% p3 c' v <mvc:annotation-driven />
3 f5 z" |! c! o2 w. O <!-- 视图解析器 -->
- u9 \& `' V/ i) x7 e4 K, \ <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
' S% m* ]+ f) ^2 H1 s8 T* U <property name="prefix" value="/WEB-INF/jsp/" />* F: B/ c) v, ~7 N1 N7 N% f
<property name="suffix" value=".jsp" />
3 N. }7 W/ H1 q, \( j% j </bean>& U; p1 l& H) Q/ m
( h& n6 d5 f: \% v
<!-- 异常解析器 -->
8 K" y& |) L# l$ } <!-- <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
0 u2 G" @; o Z2 u) x( | {, h <property name="defaultErrorView" value="common/error" />9 m2 N! k S8 r* r4 ? L
</bean> -->1 d6 Z+ O4 i$ w1 V
& k$ P6 A. V5 o- C7 k. C <!-- 拦截器 -->
. P7 c7 i4 U, ?) |4 a% i <!-- <mvc:interceptors>
$ G4 G3 a& y W" E- Q <mvc:interceptor>
- f. G `6 U) [% X <mvc:mapping path="/admin/*/*" />
* p v% k. ]1 K <bean class="com.filter.CommonInterceptor"></bean>1 K! Y1 V7 E" C0 c3 h# B
</mvc:interceptor>7 Q5 D% ?# Y5 I+ M0 v3 G- P2 K0 A* [
</mvc:interceptors> -->. B+ W3 `& N. N7 a: N
% Z! j* i, L% v. _3 c! L4 }3 m( H <!-- 上传文件相关的配置 -->
7 k) n! B; j! e/ W <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">* Y0 J2 H c, X: h0 y. ?
<property name="defaultEncoding" value="utf-8" />
7 K/ B7 n! s" ^) _" P" L <property name="maxUploadSize" value="104857600" />
! }- g! }$ ~5 _7 m <property name="maxInMemorySize" value="4096" />9 O0 ?% |9 {2 H2 @+ t7 x4 ~) T+ k+ E
</bean>; I5 O9 \: C4 r' c: g; t- _& \. O
</beans> 复制代码 8 Q" N+ ]* V$ m$ ^
2 F7 ?4 e ]0 g6 S5 d
7 e5 ^4 E9 N, G7 g s
SpringMVC+hibernate4.3+Spring4.1整合案例
- @' X/ ?9 b& D2 [" X" Y- ~" I5 { & Y* p# h* ^" D. V
我的日常 1、本主题所有言论和图片纯属会员个人意见,与本社区立场无关2、本站所有主题由该帖子作者发表,该帖子作者与我的日常 享有帖子相关版权3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和我的日常 的同意4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意7、我的日常 管理员和版主有权不事先通知发贴者而删除本文
JAVA爱好者①群:
JAVA爱好者②群:
JAVA爱好者③ :