Advanced Spring Framework.ppt
《Advanced Spring Framework.ppt》由会员分享,可在线阅读,更多相关《Advanced Spring Framework.ppt(59页珍藏版)》请在麦多课文档分享上搜索。
1、Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Advanced Spring Framework,Rod Johnson CEO Interface21 ,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is pro
2、hibited.,Aims,Understand the capabilities of the Spring Framework component model, and how you can use them to add new power to your POJO-based applications,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Agenda,Spring co
3、mponent model fundamentals Value adds out of the box User extension points Spring 2.0 configuration extensions Spring 2.1: New Scaling out the Spring component model,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,What Is
4、 Spring?,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Much More Than an IoC Container,Core component model + Services + Patterns (Recipes) + Integration (Ecosystem) + Portability (Runs everywhere) = Universal POJO prog
5、ramming modelEmbraced by more and more enterprise vendors,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Simple Object,Enabling Technologies,Simple Object,Dependency Injection,AOP,Portable Service Abstractions (PSA),Copy
6、right 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Simple POJO,public class DefaultWeatherService implements WeatherService public String getShortSummary(String location) .public String getLongSummary(String location) .public vo
7、id update(String location, WeatherData newData)No special requirements No dependencies on Spring,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Applying Declarative Transactions,Pointcut identifies business service metho
8、ds,Advice adds behavior. This advice makes business services transactional.,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Value add: Exporting a Remote Endpoint,Can add any number of server side Exporters for each Sprin
9、g managed bean Dont need to write any Java code,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Remote Client: POJO,public class MyClient private WeatherService ws;public void setWeatherService(WeatherService ws) this.ws
10、= ws;/ Business methods omitted ,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Configuring the Remote Client POJO,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written perm
11、ission is prohibited.,Unit Testing the Dependency Injected Client,public void testForMyClient() MyClient mc = new MyClient();mc.setWeatherService(myMockService);/ Test mc Can simply inject proxy into client Imagine how much harder testing would be if we had coded the lookup method in the client,Copy
12、right 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Value add: Java Management Extensions (JMX) API Export,Can expose any bean as a JMX API MBean without writing JMX API code,Copyright 2004-2007, Interface21 Ltd. Copying, publish
13、ing, or distributing without expressed written permission is prohibited.,Extension Point: Auditing Aspect,Spring container can weave any managed POJO with aspects This aspect monitors access to the methods that ask for weather summary strings Single code module addresses single requirement (auditing
14、) Type safe with argument bindingAspect public class WeatherMonitorAuditAspect After(“execution(String *.WeatherService.*(String) & args(location) & this(ws)“)public void onQuery(String location WeatherService ws) / Location and WeatherService are bound/ to the aspect ,Pointcut identifies the method
15、s that should be affected,Advice method contains code to execute,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Applying the Aspect,Ensure an tag is used to turn on automatic application of any AspectJ aspects found in t
16、he contextSimply define the aspect as a Spring bean,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,User Extension Points,The Spring IoC container provides many extension points Can easily modify the behavior of the conta
17、iner to do custom annotation processing, specific callbacks, validation etc. or even to wrap managed objects in proxies For example: FactoryBeanobject configured by the container that creates a component, introducing a level of indirection BeanPostProcessorcalled on every bean instantiation BeanFact
18、oryPostProcessorcan modify container metadata BeanDefinitionprovides ability to add custom metadata for processing by post processors,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,User Extension Point Example,Example: I
19、ntroducing a LogAware interface Components implementing this are given a log instanceThe AccountService bean needs a Log:public class AccountService implements LogAwareprivate Log log;public void setLog(Log log) this.log = log;/ Business methods omitted. ,Copyright 2004-2007, Interface21 Ltd. Copyin
20、g, publishing, or distributing without expressed written permission is prohibited.,User Extension Point Example (Cont.),public class LogInjectingBeanPostProcessor implements BeanPostProcessor public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException if (bean i
21、nstanceof LogAware) injectLog(LogAware) bean);return bean;public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException return bean; ,Called as every bean is initialized,Return value can be any object that is type compatible with the bean being processed,Copyright
22、2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Activating a BeanPostProcessor,Like most Spring IoC extension points, simply define as a bean Automatically gets applied to all other beans Customizes the behavior of the container,Co
23、pyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,Agenda,Spring component model fundamentals Value adds out of the box User extension points Spring 2.0 configuration extensions Dynamic language support Scaling out the Spring
24、component model,Copyright 2004-2007, Interface21 Ltd. Copying, publishing, or distributing without expressed written permission is prohibited.,XML Configuration Extensions in Spring 2.0: Important New Extension Point,A bean definition is a recipe for creating one object Spring 2.0 added the ability
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ADVANCEDSPRINGFRAMEWORKPPT
