Java应用框架Spring实验指导书.doc

Similar documents
EJB-Programming-4-cn.doc

IoC容器和Dependency Injection模式.doc

-i-

Microsoft Word - 强迫性活动一览表.docx

untitled

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

「香港中學文言文課程的設計與教學」單元設計範本

全唐诗28

untitled

北 风 网 讲 师 原 创 作 品 ---- 仅 供 学 员 内 部 交 流 使 用 前 言 吾 尝 终 日 而 思 矣, 不 如 须 臾 之 所 学 也 ; 吾 尝 跂 而 望 矣, 不 如 登 高 之 博 见 也 登 高 而 招, 臂 非 加 长 也, 而 见

2. AOP 底层技术实现 小风 Java 实战系列教程 关键词 : 代理模式 代理模型分为两种 : 1) 接口代理 (JDK 动态代理 ) 2) 子类代理 (Cglib 子类代理 ) 需求 :CustomerService 业务类, 有 save,update 方法, 希望在 save,updat

II II

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

一、

尿路感染防治.doc

509 (ii) (iii) (iv) (v) 200, , , , C 57

新・解きながら学ぶJava

Microsoft Word - MP2018_Report_Chi _12Apr2012_.doc

南華大學數位論文

李天命的思考藝術

皮肤病防治.doc

性病防治

中国南北特色风味名菜 _一)

全唐诗24


2. 我 沒 有 說 實 話, 因 為 我 的 鞋 子 其 實 是 [ 黑 色 / 藍 色 / 其 他 顏 色.]. 如 果 我 說 我 現 在 是 坐 著 的, 我 說 的 是 實 話 嗎? [ 我 說 的 對 還 是 不 對 ]? [ 等 對 方 回 答 ] 3. 這 是 [ 實 話 / 對 的

Microsoft Word - Paper on PA (Chi)_ docx

_Chi.ps, page Preflight ( _Chi.indd )

Page i

优迈科技教学大纲2009版本

Microsoft Word - Entry-Level Occupational Competencies for TCM in Canada200910_ch _2_.doc

<4D F736F F D203938BEC7A67EABD7B942B0CAC15AC075B3E6BF57A9DBA5CDC2B2B3B92DA5BFBD542E646F63>

緒 言 董 事 會 宣 佈, 為 能 更 具 效 率 調 配 本 集 團 內 的 資 金 有 效 降 低 集 團 的 對 外 貸 款, 並 促 進 本 集 團 內 公 司 間 的 結 算 服 務, 於 2016 年 9 月 30 日, 本 公 司 中 糧 財 務 與 管 理 公 司 訂 立 財 務

穨學前教育課程指引.PDF

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

眼病防治

中国南北特色风味名菜 _八)

39898.indb

穨ecr2_c.PDF

電腦相關罪行跨部門工作小組-報告書

i

发展党员工作手册

i

基于CDIO一体化理念的课程教学大纲设计

智力测试故事

目 录 院 领 导 职 责... 1 院 长 职 责... 1 医 疗 副 院 长 职 责... 1 教 学 副 院 长 职 责... 2 科 研 副 院 长 职 责... 2 后 勤 副 院 长 职 责... 3 主 管 南 院 区 副 院 长 职 责... 3 党 委 书 记 职 责... 4

<4D F736F F D20A4A4B0EAB371AB4FB3E65FA4A4A4E5AAA95F5F >

(b) 3 (a) (b) 7 (a) (i) (ii) (iii) (iv) (v) (vi) (vii) 57

(i) (ii) (iii) (iv) (v) (vi) (vii) (viii) (ix) (x) (xi) 60.99%39.01%

奇闻怪录

<4D F736F F D205B345DB5D8AE4CACD AECAAFC5C1C9C1DCBDD0AB48A4CEB3F8A657AAED>


群科課程綱要總體課程計畫書

没 有 多 余 的 Contruol 或 Action 了 原 来 Domain 层 被 服 务 层 Service layer 遮 挡, 在 右 边 图 中, 则 Domain 层 直 接 暴 露 给 前 台 了, 没 有 被 遮 挡, 裸 露 了 这 样 一 步 到 位 实 现 领 域 模 型

30,000,000 75,000,000 75,000, (i) (ii) (iii) (iv)

第 二 輯 目 錄.indd 2 目 錄 編 寫 說 明 附 : 香 港 中 學 文 憑 中 國 語 文 科 評 核 模 式 概 述 綜 合 能 力 考 核 考 試 簡 介 及 應 試 技 巧 常 用 實 用 文 文 體 格 式 及 寫 作 技 巧 綜 合 能 力 分 項 等 級 描 述 練 習 一

Microsoft Word - Panel Paper on T&D-Chinese _as at __final_.doc

就財務委員會委員審核2015至16年度開支預算所提出初步問題的答覆

I. 1-2 II. 3 III. 4 IV. 5 V. 5 VI. 5 VII. 5 VIII. 6-9 IX. 9 X XI XII. 12 XIII. 13 XIV XV XVI. 16

江苏宁沪高速公路股份有限公司.PDF

我 非 常 希 望 该 小 组 的 建 议 尤 其 是 其 执 行 摘 要 能 受 到 将 于 2000 年 9 月 来 纽 约 参 加 千 年 首 脑 会 议 的 所 有 领 导 人 的 注 意 这 次 历 史 性 的 高 级 别 会 议 提 供 了 一 个 独 特 的 机 会 使 我 们 能 够

RunPC2_.doc

榫 卯 是 什 麼? 何 時 開 始 應 用 於 建 築 中? 38 中 國 傳 統 建 築 的 屋 頂 有 哪 幾 種 形 式? 40 大 內 高 手 的 大 內 指 什 麼? 42 街 坊 四 鄰 的 坊 和 街 分 別 指 什 麼? 44 北 京 四 合 院 的 典 型 格 局 是 怎 樣 的

心理障碍防治(下).doc

(Chi)_.indb

14A 0.1%5% 14A 14A

绝妙故事

穨_2_.PDF

Microsoft Word - 第3章.doc

I

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

捕捉儿童敏感期

世界名画及画家介绍(四).doc

Microsoft PowerPoint - ch6 [相容模式]

Microsoft Word - John_Ch_1202

飞行模拟设备的鉴定和使用规则

untitled

Teaching kit_A4_part4.indd

全唐诗50

樹 木 管 理 專 責 小 組 報 告 人 樹 共 融 綠 滿 家 園

mvc

输入 project name 选择完成

Microsoft Word - NCH final report_CHI _091118_ revised on 10 Dec.doc

中医疗法(下).doc

施 的 年 度 維 修 工 程 已 於 4 月 15 日 完 成, 並 於 4 月 16 日 重 新 開 放 給 市 民 使 用 ii. 天 水 圍 游 泳 池 的 年 度 維 修 工 程 已 於 3 月 31 日 完 成, 並 於 4 月 1 日 重 新 開 放 給 市 民 使 用 iii. 元

Transcription:

Java Spring lyaiqing@126.com

Spring 1. Spring jsp 001 Spring name mike password name Tom password 123456 Mysql

1. a) i. mysql Empl, sql 1. 2. a) Eclipse Web Project :myspring b) jar i. / ii. spring-framework-3.2.0.release libs jar MySpring lib / jar MySpring lib c) i. src ii. com.oracle.csg.entity 1. com.oracle.csg.entity Empl Serializable 2. Empl set get a) name String private b) password String private src com.oracle.csg.dao 1. com.oracle.csg.dao EmplDao 2. ErmplDao Spring jdbctemplate jdbctemplate private set 3. queryempl(); a) public int String name b) i. hql 1. "from Empl where name=?

ii. iii. jdbstemplate queryforlist(string hql,object args) hql name List list list size() 4. save a) public b) void c) String name d) String password i. String hql ii. 1. String hql="insert into Empl values(?,?)"; String name password jdbctemplate update() hql 1. jdbctemplate.update(hql,newstring[]{name,passwor d}); d) i. / ii. iii. applicationcontext.xml src applicationcontext.xml 1. bean id datasource class org.apache.commons.dbcp.basicdatasource 2. property datasource ( url ) a) name driverclassname value com.mysql.jdbc.driver b) name: url value: jdbc:mysql:localhost:3306/empl url c) name username value root d) name password value root applicationcontext.xml spring jdbctemplate 1. bean a) id jdbctemplate b) class org.springframework.jdbc.core.jdbctemplate 2. bean property property a) name datasource b) ref datasource

iv. applicationcontext.xml EmplDao 1. bean a) id: empldao b) class com.oracle.csg.dao.empldao 2. bean property property a) name jdbctemplate b) ref jdbctemplate e) i. src com.oracle.csg.service ii. iii. iv. com.oracle.csg.service EmplService UserDao userdao private set check String name String password 1. empldao queryempl(string name) name int count 2. count 0 true empldao.save String name,string passwordname password false applicationcontext.xml EmplService 1. bean a) id EmplService b) class com.oracle.csg.service 2. bean property a) id empldao b) class com.oracle.csg.service.empldao f) i. src com.oracle.csg.servlet ii. com.oracle.csg.servlet servlet CheckServlet iii. iv. CheckServlet EmplService emplservice private dopost doget 1. this.dopost(request, response); v. request.getparameter String arg vi. vii. viii. WebApplicationContextUtils getwebapplicationcontext(this.getservletcontext()) WebApplicationContext ct cx.getbean("emplservice") id emplservice bean EmplService emplservice emplservice check(string name String password) true allow.jsp

ix. 1. request.getrequestdispatcher("allow.jsp").forward(request, response forbid.jsp jsp WebContent/ x. web.xml welcome-file index.jsp regist.jsp xi. xii. <display-name> listener spring spring 1. <listener-class> org.springframework.web.context.contextloaderlistener</listenerclass> listener <context-param> 1. param-name contextconfiglocation 2. param-value classpath:applicationcontext.xml

Spring IOC 1. Spring 001 1. : a) Eclipse java Project : SpringDemo001 b) src jar i. Build Path Configure Build Path ii. iii. Libraries Add Library.. User Library User Libraries. New.. jar springlib springlib Add External JARS. \ commons-logger.jar spring-framework-3.2.0.release\libs jar jar c) src com.oracle.csg.spring i. com.oracle.csg.spring UserDao ii. iii. 1. sayhello String arg void src User UserDao 1. User sayhello String arg a) System.out.println(arg) src UserService

iv. 1. UserDao userdao private 2. adduser() void public a) userdao sayhello(string arg) "hello " 3. UserService \ applicationcontext.xml src 1. bean id User class com.oracle.csg.spring.userservice 2. bean id UserService Class com.oracle.csg.spring.userservice bean constructor-arg User a) ref User v. src Test 1. Test applicationcontext.xml a) ApplicationContext ct=new ClassPathXmlApplicationContext("applicationContext.xml") b) ct getbean("userservice") id UserService bean UserService UserService user c) user adduser() d) Test 2. : a) UserService, UserService userdao set b) applicationcontext.xml bean constructor-arg property i. name userdao ii. ref User c) Test

Spring IOC 1. BeanFactory ApplicationContext bean Bean 001 Spring 1. : a) \ SpringDemo003 eclipse i. SpringDemo003 jar jar jar ii. SpringDemo003 Book Book set b) src applicationcontext.xml bean id Book class com.oracle.csg.spring.book i. bean property property name value 1. name name value 2. name price value 290.00 3. name page value 2648 2. : a) BeanFactory i. com.oracle.csg.spring beanfactorytest main

ii. 1. Resource res a) new FileSystemResource( "src/applicationcontext.xml") 2. BeanFactory BeanFactory bf a) new XmlBeanFactory(res) 3. bf getbean Book Book spring bean Book book 4. book tostring() book b) ApplicationContext i. applicationtest main ii. 1. spring ApplicationContext app: a) new ClassPathXmlApplicationContext("applicationContext.xml") 2. app getbean( Book ) Book Book book 3. book tostring book 002 Bean 1. :

a) \ SpringDemo004 eclipse SpringDemo04 spring jar ( jar, spring jar ) i. SpringDemo04 Car Type 2. : 1. Type String type set get 2. Car Type type Double price set tostring a) Bean i. src applicationcontext.xml ii. Bean id BMW class iii. iv. com.oracle.csg.spring.type 1. Bean property property a) name type b) value BMW Bean id type class com.oracle.csg.spring.car 1. Bean property property a) name type b) ref BMW BMW Bean 2. Bean property a) name price b) value 670000 com.oracle.csg.spring Test 1. ApplicationContext app a) new ClassPathXmlApplicationContext("applicationContext.xml") 2. app getbean(string arg) Car Car Car car 3. car tostring v. Test b) Bean i. src applicationcontext.xml ii. Bean Bean iii. Bean 1. id Scar 2. class com.oracle.csg.spring.car Bean constructor-arg constructor-arg

iv. 1. name type 2. ref BMW BMW Bean Bean constructor-arg constructor-arg 1. name price 2. value 580000 v. com.oracle.csg.spring Test vi. 1. app getbean(string arg) SCar Car Car Scar 2. Scar tostring Test

Spring IOC 1. 2. 3. 001 1. : a) \ SpringDemo005 eclipse : SpringDemo005 spring jar ( jar, spring jar ) 2. : a) src applicationcontext.xml src bean.xml b) bean.xml i. Bean id BENZ ii. 1. Bean property value BENZ Bean id SCar 1. Bean property ref BENZ 2. property value 580000 c) com.oracle.csg.spring Test

i. new ii. ClassPathXmlApplicationContext("applicationContext.xml") "applicationcontext.xml" 1. new String[]{"applicationContext.xml","bean.xml"} 1. app getbean(string arg) Scar Car Car Scar 2. Scar tostring Scar d) Test 002 Bean 1 Bean 2 Bean 1. : a) \ SpringDemo006 eclipse 2. : 1. SpringDemo006 spring jar ( jar, spring jar ) 2. SpringDemo006 Parent Parent Son son set get

3. SpringDemo006 Son Son name age sex set Son tostring a) Bean i. src applicationcontext.xml ii. iii. iv. bean bean 1. id Son 2. class com.oracle.csg.spring.son bean property Son property 1. name name 2. value property sex age sex age 5 v. Parent bean Parent bean Son vi. bean 1. bean id Parent calss com.oracle.csg.spring.parent 2. bean property name Son 3. property ref ref bean Son com.oracle.csg.spring Test b) Bean ii. iii. i. src bean.xml iv. applicationcontext.xml Parent bean bean.xml bean id Son Son1 applicationcontext.xml Parent bean ref bean Son1 com.oracle.csg.spring ParentTest Test ParentTest 1. a) ApplicationContext parent=new ClassPathXmlApplicationContext("bean.xml"); 2. ApplicationContext app=new ClassPathXmlApplicationContext("applicationContext.xml") applicationcontext.xml a) new String[]{"applicationContext.xml"},parent 3. ParentTest

003 null 1 null 2 1. : a) \ SpringDemo007 eclipse 2. : 1. SpringDemo007 spring jar ( jar, spring jar ) 2. SpringDemo007 Goods Goods price( ) weight( ) size( ) set Goods tostring

3. SpringDemo007 Warehouse Warehouse Goods goods set get a) null i. src applicationcontext.xml ii. iii. iv. bean bean 1. id Goods 2. class com.oracle.csg.spring.goods bean property Goods property 1. name price 2. value 300.00 bean property name size 1. property value value v. bean property name weight vi. 1. property null Test b) i. applicationcontext.xml bean ii. iii. iv. 1. id Warehouse 2. class com.oracle.csg.spring.warehouse bean property property 1. name goods.price 2. value 150.00 property 1. name goods.weigth 2. value 50.23 property 1. name goods.weight 2. value 5 v. Warehouse, goods. vi. 1. private Goods goods=new Goods(); CascadeTest CascadeTest 004 1 ArrayList

2 HashSet 3 HashMap

1. : a) \ SpringDemo008 eclipse 2. : 1. SpringDemo008 spring jar ( jar, spring jar ) 2. SpringDemo008 ListStudents SetStudent MapStudent name( ) grade( subject( ) set get a) ArrayList i. src applicationcontext.xml ii. bean bean iii. iv. 1. id Student 2. class com.oracle.csg.spring.entity.liststudent bean property Goods property 1. name subjects subject list property list 1. value PE music English v. ListTest com.oracle.csg.spring.test ListTest b) HashSet i. applicationcontext.xml bean ii. 1. bean id Student1 class com.oracle.csg.spring.entity.setstudent 2. property list set SetTest com.oracle.csg.spring.test SetTest c) HashMap i. applicationcontext.xml bean 1. id Students2 ii. iii. 2. class com.oracle.csg.spring.entity.mapstudent bean property 1. name subjects property map map entry 1. entry key value a) key value value b) value English

iv. entry key value Value MUSIC MapTest MapTest 005 1. : a) \ SpringDemo009 eclipse 2. : 1. SpringDemo009 spring jar ( jar, spring jar ) 2. SpringDemo009 Teacher. Teacher String name set get 3. SpringDemo009 Student Student Teacher teacher String name grade set get a) i. src applicationcontext.xml ii. p 1. bean a) xmlns:p="http://www.springframework.org/schema/p" Teacher bean property class 1. p:name= teacher name

iii. iv. Student bean property class p 1. p:teacher-ref="teacher" Teacher bean 2. p:name=" " name 3. p:grade=" " Test Test 006 byname bytype 3. : a) \ SpringDemo010 eclipse 4. :

1. SpringDemo010 spring jar ( jar, spring jar ) 2. SpringDemo010 Teacher. Teacher String name set get 3. SpringDemo010 Student Student Teacher teacher String name grade set get a) byname i. applicationcontext.xml Student bean ii. iii. iv. 1. <property name="teacher" ref="teacher"></property> Student bean class autowire byname byname Student bean Student teacher Teacher bean id teacher Test Test b) bytype i. autowire byname bytype bytype ii. bean id Test c) i. id Student1 bean class autowire constructor ii. iii. iv. 1. <constructor-arg type="com.oracle.csg.spring.teacher" ref="teacher"></constructor-arg> com.oracle.csg.spring Test getbean Student Student1 1. Student stu=(student) app.getbean("student"); Test

1. Bean 2. FactoryBean Spring IOC 001 singleton prototype singleton : prototype 1. SpringDemo012 eclipse 1. SpringDemo012 spring jar ( jar, spring jar )

2. SpringDemo012 Teacher. Teacher String name set get 3. SpringDemo012 Student Student Teacher teacher String name grade set get 2. singleton applicationcontext.xml teacher bean class scope singleton Test com.oracle.csg.spring Test teacher bean == Student1 Student2 bean == Student1 Student2 bean teacher == 3. prototype teacher bean scope prototype Test 002 Bean( ) getobject

1. SpringDemo013 eclipse 1. SpringDemo013 spring jar ( jar, spring jar ) 1. SpringDemo013 Pet Pet String owner String name variety set get 2. applicationcontext.xml Pet Bean FactoryBean Bean com.oracle.csg.spring PetBean FactoryBean FactoryBean PetBean applicationcontext.xml bean class com.oracle.csg.spring. PetBean 2. getobject PetBean getobject Pet pet Pet set pet name variety owner pet Test Test getobject PetBean String petinfo private set split String arg petinfo String info getobject Pet pet Info pet pet.setname(info[0]); pet.setowner(info[1]); pet.setvariety(info[2]); pet applicationcontext.xml Pet bean property name petinfo value,, Test

003 Bean( ) issingleton() true false 1. SpringDemo014 eclipse 2. SpringDemo014 spring jar ( jar, spring jar ) 3. SpringDemo014 Owner Owner String name set get 4. SpringDemo014 Pet Pet Owner owner String name variety set get 5. applicationcontext.xml Pet Bean FactoryBean Bean com.oracle.csg.spring PetBean FactoryBean

FactoryBean PetBean applic ationcontext.xml bean class com.oracle.csg.spring. PetBean 2. issingleton() : PetBean getobject() Pet, pet. pet name :Variety Owner PetBean issingleton() false true Test true issingleton() true issingleton() false Test 3. getobjecttype() FactoryBean Pet bean getobjecttype Pet.class FactoryBean Bean Pet

1. Spring IOC 001 save jack 1. mysql Empl, sql

SpringDemo015 eclipse 1. SpringDemo015 spring jar ( jar, spring jar ) 2. SpringDemo015 com.oracle.csg.entity Empl set get 3. com.oracle.csg.dao Dao Dao save jack 1111 4. applicationcontext,xml applicationcontext.xml datasource bean url username password 2. bean Dao save System.out.println("Dao"); Dao @Repository @Autowired private JdbcTemplate jdbctemplate; com.oracle.csg.service Service Service @Service service Dao dao dao @Autowired service save public void System.out.println("Service"); dao save() com.oracle.csg.controller ControllerController @Controller Controller Service service Controller save public void System.out.println("Controller"); servic e save() 3. Spring

applicationcontext.xml context beans xmlns:context= http://www.springframework.org/schema/context beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd context:component-scan base-package com.oracle.csgcom.oracle.csg Test empldao.save(); emplservice.save(); emplcontroller.save();

1. Jdk 2. cglib Spring AOP 001 JDK 1. SpringDemo016 eclipse 1. SpringDemo016 spring jar ( jar, spring jar ) 2. SpringDemo016 com.oracle.csg.spring Eat Eat Eating 2. JDK Test com.oracle.csg.spring IEat Eating void Eat Ieat HandlerEat InvocationHandler invoke(object arg0, Method arg1, Object[] arg2)

System.out.println(" "); System.out.println(" "); HandlerEat eat HandlerEat Method arg1 invoke(obj, args) eat arg2 Test Eat eat HandlerEat eat HandlerEat handler Proxy newproxyinstance(arg0, arg1, arg2) eat.getclass().getclassloader() eat.getclass().getinterfaces() handler Ieat eathandler eathandler Eating Test 002 CGLIB 1. SpringDemo017 eclipse 1. SpringDemo017 spring jar CGLIB jar ( jar, spring jar jar ) 2. SpringDemo017 com.oracle.csg.spring Eat Eat Eating

2. CGLIB com.oracle.csg.spring CGProxy MethodInterceptor Enhancer en getproxy(class clazz) void public en setsuperclass(class clazz) clazz superclass en setcallback(callback Callback) this en create intercept Object arg0, Method arg1, Object[] arg2,methodproxy arg3 System.out.println(" "); System.out.println(" "); intercept arg3 invokesuper(arg0, arg1) arg0 arg1 arg0 arg2 Object result Test CGProxy cg cg getproxy clazz Eat.class Eat eat eat Eating Test

1. Spring AOP 001 1. SpringDemo018 eclipse 1. SpringDemo018 spring jar ( jar, spring jar ) 2. SpringDemo018 com.oracle.csg.spring PenguinPenguin SleepAndBeat. 3. com.oracle.csg.spring FirstPenguin FirstPenguin Penguin FirstPenguin Penguin SleepAndBeat 2. com.oracle.csg.spring GreetBeforeAdvice MethodBeforeAdvice GreetBeforeAdvice before(method arg0, Object[] arg1, Object arg2) Test FirstPenguin pe BeforeAdvice advice=new GreetBeforeAdvice(); ProxyFactory ProxyFactory pf pf settarget Object target pe

pf setaddvice Advice advice advice pf getproxy() Penguin proxy proxy SleepAndBeat Test 002 1. SpringDemo019 eclipse 1. SpringDemo019 spring jar ( jar, spring jar ) 2. SpringDemo019 com.oracle.csg.spring PenguinPenguin EatingAndSleep. 3. com.oracle.csg.spring FirstPenguin FirstPenguin Penguin FirstPenguin Penguin EatingAndSleep 2. com.oracle.csg.spring GreetAfterAdvice AfterReturningAdvice GreetAfterAdvice afterreturning(object arg0, Method arg1, Object[] arg2, Object arg3) src applicationcontext.xml p xmlns:p= http://www.springframework.org/schema/p bean id target class com.oracle.csg.spring.firstpenguin bean id afteradvice class com.oracle.csg.spring.greetafteradvice bean id Penguin class

org.springframework.aop.framework.proxyfactorybean bean p p:proxyinterfaces="com.oracle.csg.spring.penguin" Penguin p:interceptornames="afteradvice" afteradvice bean p:target-ref="target" Test com.oracle.csg.spring Test main ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml") ctx getbean String arg Penguin proxy proxy EatingAndSleep Test

1. Spring AOP 001 1. SpringDemo022 eclipse 1. SpringDemo022 spring jar ( jar, spring jar ) 2. SpringDemo022 com.oracle.csg.spring FirstPenguin FirstPenguin Sleep Beat. 3. com.oracle.csg.spring SecondPenguin SecondPenguin Sleep 2. com.oracle.csg.spring GreetBeforeAdvice MethodBeforeAdvice GreetBeforeAdvice before(method method, Object[] args, Object arg2) com.oracle.csg.spring GreetAdvisor, StaticMethodMatcherPointcutAdvisor StaticMethodMatcherPointcutAdvisor matches(method arg0, Class<?> arg1) arg0 getname equals Sleep GreetAdvisor getclassfilter() ClassFilter public new ClassFilter() ClassFilter

matches(class<?> arg0) FirstPenguin return FirstPenguin.class.isAssignableFrom(arg0); src applicationcontext.xml p xmlns:p= http://www.springframework.org/schema/p bean id target1 class com.oracle.csg.spring.firstpenguin bean id target2 class com.oracle.csg.spring.secondpenguin bean id greetadvice class com.oracle.csg.spring.greetbeforeadvice bean bean id greetadvisor Class com.oracle.csg.spring.greetadvisor bean p p:advice-ref="greetadvice" bean id parent abstract true class org.springframework.aop.framework.proxyfactorybean bean p p:interceptornames="greetadvisor " greetadvisor bean p:proxytargetclass="true" bean id first parent parent p:target-ref target1 bean id second parent parent p:target-ref target2 Test

002 1. SpringDemo023 eclipse 1. SpringDemo023 spring jar ( jar, spring jar ) 2. SpringDemo023 com.oracle.csg.spring FirstPenguin FirstPenguin Sleep Beat. 3. com.oracle.csg.spring SecondPenguin SecondPenguin Sleep 2. com.oracle.csg.spring GreetBeforeAdvice MethodBeforeAdvice GreetBeforeAdvice before(method method, Object[] args, Object arg2) src applicationcontext.xml p xmlns:p= http://www.springframework.org/schema/p bean id target1 class com.oracle.csg.spring.firstpenguin bean id target2 class com.oracle.csg.spring.secondpenguin bean id greetadvice class com.oracle.csg.spring.greetbeforeadvice bean bean id regexadvisor Class org.springframework.aop.support.regexpmethodpointcutadvisor bean p

p:advice-ref="greetadvice" bean p. p:pattern=".*sleep.*"( Sleep ) bean id parent abstract true class org.springframework.aop.framework.proxyfactorybean bean p p:interceptornames="regexadvisor" regexadvisor bean p:proxytargetclass="true" bean id first parent parent p:target-ref target1 bean id second parent parent p:target-ref target2 Test

1. struts2 001 struts2 1. SpringDemo027 eclipse 1. SpringDemo027 spring jar ( jar, spring jar ) 2. SpringDemo027 com.oracle.csg.spring Student Student (subject) (subject), set get 3. com.oracle.csg.spring StudentService StudentService check score 60 false 60 true 4. jsp 1. struts2 web.xml WebContent/WEB-INF/web.xml web.xml struts2

<filter> <filter> <filter-name> <filter-class> struts2 org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter <filter-mapping> <filter-mapping> <filter-name> <url-pattern> struts2 ( filter filter-name ) /* <context-param> <context-param> <param-name> <param-value> contextconfiglocation /WEB-INF/classes/applicationContext.xml <listener> ContextLoaderListener <listener> <listener-class> org.springframework.web.context.contextloaderlistener com.oracle.csg.spring CheckAction ActionSupport CheckAction student set get service set student Student service StudentService execute() public String throws Exception execute() service checkstudent.getsubject() student.getscore() ispass ispass false error success struts.xml src struts.xml <struts> <package>, package <package> name default extends struts-default <package> <action><action> name CheckAction name form.jsp action class checkaction checkaction <action> <result> name success name error applicationcontext.xml congratulation.jsp warn.jsp src applicationcontext.xml bean

id studentservice class com.oracle.csg.spring.studentservice bean id checkaction id struts.xml <action> class class com.oracle.csg.spring.checkaction bean <property> CheckAction service studentservice bean name service ref studentservice http://localhost:8080/springdemo27/form.jsp 59 80. struts.xml <action> class com.oracle.csg.spring.checkaction applicationcontext.xml http://localhost:8080/springdemo27/form.jsp 59 80. src struts.properties struts.objectfactory.spring.autowire=type applicationcontext.xml bean id studentservice studentservice1 struts.properties ## struts.xml <package> <constant> name struts.objectfactory.spring.autowire value type

1. spring Quartz 001 spring Quartz simpletrigger crontrigger 4. SpringDemo031 eclipse 5. SpringDemo031 spring jar ( jar, spring jar ) 6. com.oracle.csg.spring Service Hello(), :

a) Hello!Use Quartz in Spring!"+new Date() 5. JobDetail applicationcontext.xml Service bean bean id service class com.oracle.csg.spring.service bean id jobdetail class org.springframework.scheduling.quartz.methodinvokingjobdetailfactorybean bean p applicationcontext.xml p p:targetobject-ref service bean p:targetmethod" service p:concurrent false job 6. Trigger simpletrigger beanbean id simpletrigger class org.springframework.scheduling.quartz.simpletriggerfactorybean p:jobdetail-ref jobdetail p:startdelay 2000 p:repeatinterval 3000 p:repeatcount 3 CronTrigger beanbean id crontrigger class org.springframework.scheduling.quartz.crontriggerfactorybean p:jobdetail-ref jobdetail p:cronexpression 0/3 * * * *? schedualer 3 beanbean id scheduler class org.springframework.scheduling.quartz.schedulerfactorybean bean property name: triggers property list list refref bean simpletrigger Test ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml"); ctx getbean String arg schedual Schedual sch

sch start Test applicationcontext.xml id scheduler bean property list ref bean crontrigger Test

Spring Hibernate 1. spring hibernate 001 hibernate Mysql 1. SpringDemo037 eclipse 1. sql sql mysql 2. SpringDemo038 aopalliance spring mysql dbcp hibernate jar ( jar, jar ): 3. com.oracle.csg.spring.dao EmplDao SaveOrUpdate Empl empl 4. com.oracle.csg.spring.dao.impl EmplDaoImpl EmplDao 5. src applicationcontext.xml sessionfactory hibernatetemplate EmplDaoImpl 2. Spring hibernate

com.oracle.csg.spring.listener MyListener DefaultSaveOrUpdateEventListener MyListener onsaveorupdate SaveOrUpdateEvent event void public throws HibernateException event getobject() getclass() "SaveOrUpdate Entity classname:" "SaveOrUpdate Entity classname:"+event.getobject().getclass()) event getobject Object object instanceof object Empl object Empl object Empl Empl empl empl getname() getdept() name dept super.onsaveorupdate(event); applicationcontext.xml sessionfactory <bean> <property> name eventlisteners <property> <map> <map> < entry ><entry> key save-update <entry> <bean><bean> class com.oracle.csg.spring.listener.mylistener Test Empl empl empl set name Jack sex fale dept Sale dao SaveOrUpdate(Empl empl) empl Test Spring Hibernate 1. spring

002 1. SpringDemo038 eclipse 1. sql sql mysql 2. SpringDemo038 aopalliance spring mysql dbcp hibernate jar ( jar, jar ): 3. com.oracle.csg.spring.dao EmplDao SaveOrUpdate Empl empl 4. com.oracle.csg.spring.dao.impl EmplDaoImpl EmplDao 5. src applicationcontext.xml sessionfactory hibernatetemplate EmplDaoImpl applicationcontext.xml <bean> <bean> id transactionmanager name org.springframework.orm.hibernate3.hibernatetransactionmanager <bean> <property> sessionfactory <property> name sessionfactory ref sessionfactory 2. TransactionProxyFactoryBean hibernate <bean> id empldaoproxy class org.springframework.transaction.interceptor.transactionproxyfactorybean <bean> <property>

<property>: name proxytargetclass value:true <property> name: transactionmanager ref transactionmanager <property> name target ref empldao <bean> <properyt> <properyt> <props> <props> > key * * empldao <prop > PROPAGATION_REQUIRED Test1 empl Jack 3. aop/tx hibernate applicationcontext.xml context aop tx TransactionProxyFactoryBean, hibernate applicationcontext.xml <tx:advice> id txadvice transaction-manager transactionmanager <tx:advice> <tx:attributes> <tx:attributes> <tx:method > name * propagation REQUIRED empldao <tx:advice> <aop:config> <aop:config> <aop:advisor> advice-ref txadvice pointcut execution(* com.oracle.csg.spring.dao.impl.empldaoimpl.*(..)) EmplDaoImpl Test2 empl Tom 4. @Transactional, hibernate aop/tx hibernate

applicationcontext <tx:annotation-driven/> com.oracle.csg.spring.dao.impl EmplDaoImpl EmplDaoImpl @Transactional(propagation=Propagation.REQUIRED) Test3 empl Marry

Spring Hibernate 1. XML 001 tx/aop, 1. SpringDemo041 eclipse 1. sql sql mysql 2. SpringDemo041 jar ( jar, jar ): 3. com.oracle.csg.spring.dao EmplDao save(empl em pl) count 4. com.oracle.csg.spring.dao.impl EmplDaoImpl EmplDao

5. src applicationcontext.xml (datasource) E mpldaoimpl jdbc transactionmanager 2. com.oracle.csg.spring.service EmplService countempl() Integer public save(empl empl) void public com.oracle.csg.spring.service.impl EmplService rviceimpl EmplDao empldao private set countempl() empldao countempl() save(empl empl) empldao save(empl empl) empl 1. tx/aop <bean> Bean <bean > id emplservice class com.oracle.csg.spring.service.impl.emplserviceimpl <bean> < property> EmplServiceImpl empldao< pr operty> name empldao ref empldao tx aop tx ao p tx < tx:advice> id txadvice transaction-manager transactionmanager < tx:advice> <tx:attributes> <tx:attributes> <tx:method> name count* read-only true propagation SUPPORTS count Support <tx:attributes> <tx:method> name save* rollback-for Exception save Exception propagation REQUIRED REQUIRED aop

<aop:config> <aop:config> <aop:pointcut><aop: pointcut> expression execution(* com.oracle.csg.spring.service.impl.*impl.*(..)) com.oracle.csg.spring.service. impl Impl id txpointcut <aop:config> <aop:advisor> <aop:advisor> advice-ref txadvice pointcut-ref txpointcut Test ctx getbean(string arg) emplservice EmplService emplservice Empl empl empl set empl name dept set name Salar sex female dept Sale service save(empl) Test mysql empl service count() Test 002 TransactionProxyFactoryBean 1. SpringDemo040 eclipse 1. sql sql mysql 2. SpringDemo040 jar ( jar, jar ):

3. com.oracle.csg.spring.dao EmplDao countempl 4. com.oracle.csg.spring.dao.impl EmplDaoImpl EmplDao 5. src applicationcontext.xml (datasource) E mpldaoimpl jdbc transactionmanager 2. com.oracle.csg.spring.service EmplService cou ntempl() Integer public com.oracle.csg.spring.service.impl EmplService rviceimpl EmplDao empldao private set countempl() empldao countempl() 3. TransactionProxyFactoryBean, <bean> <bean> id emplservice class com.oracle.csg.spring.service.impl.emplserviceimpl <bean> < property> EmplServiceImpl empldao< pr operty> name empldao ref empldao <bean> id proxyservcebean class org.springframework.transaction.interceptor.transactionproxyfactorybean <bean> <property> <property> : name transactionmanager ref transactionmanager <property> name: target ref emplservice <property> name transactionattribute <property> <props> <props> < prop> <prop> key count* count <prop> PROPAGATION_REQUIRED,readOnly Test ctx getbean(string arg) proxyservce EmplService service

service countempl()