27
Copyright 2010 TCloud Computing Inc. Spring Framework Introduction Alex Su 2010/06/14

Spring Framework Introduction

  • Upload
    alex-su

  • View
    966

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Spring Framework Introduction

Copyright 2010 TCloud Computing Inc.

Spring Framework IntroductionAlex Su2010/06/14

Page 2: Spring Framework Introduction

Agenda

Trend Micro Confidential

• Concept– IOC(Inverse of Control and Dependency Injection)–AOP(Aspect-Oriented Programming)

• Core Technologies–Architecture–Xml v.s. Annotation–SpEL–Testing

• Integration–CXF(web services and restful services)

Page 3: Spring Framework Introduction

IOC

Trend Micro Confidential

• IOC Type• Type 1 : interface injection• Type 2 : setter injection• Type 3 : constructor injection

Page 4: Spring Framework Introduction

AOP

Trend Micro Confidential

Page 5: Spring Framework Introduction

AOP

Trend Micro Confidential

Page 6: Spring Framework Introduction

AOP

Trend Micro Confidential

• Aspect• Advice• Interceptor• Introduction• Joinpoint• Pointcut• Target• Proxy• Weave

Page 7: Spring Framework Introduction

AOP

Trend Micro Confidential

Page 8: Spring Framework Introduction

AOP

Trend Micro Confidential

@Aspectclass BeforeExample { @Before("execution(* com.xyz.myapp.dao.*.*(..))") public void doAccessCheck() { // ... }}

@Aspectclass AfterReturningExample { @AfterReturning("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") public void doAccessCheck() { // ... }}

Page 9: Spring Framework Introduction

AOP

Trend Micro Confidential

@Aspectclass AroundExample { @Around("com.xyz.myapp.SystemArchitecture.businessService()") public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { // start stopwatch Object retVal = pjp.proceed(); // stop stopwatch return retVal; }}

Page 10: Spring Framework Introduction

Pointcut designator

Trend Micro Confidential

• execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)

• execution(public * *(..))• execution(* com.xyz.service.AccountService.*(..))

• within(com.xyz.service.*)• within(com.xyz.service..*)

• this(com.xyz.service.AccountService)

• target(com.xyz.service.AccountService)

Page 11: Spring Framework Introduction

Architecture

Trend Micro Confidential

Page 12: Spring Framework Introduction

Architecture

Trend Micro Confidential

Page 13: Spring Framework Introduction

Architecture

Trend Micro Confidential

• Bean Scope• Singleton• Prototype• Request• Session• Custom

Page 14: Spring Framework Introduction

Architecture

Trend Micro Confidential

Page 15: Spring Framework Introduction

Architecture

Trend Micro Confidential

Page 16: Spring Framework Introduction

Xml v.s. Annotation

Trend Micro Confidential

public class SimpleMovieLister { private MovieFinder movieFinder;

public void find() { movieFinder.find(); }

public void setMovieFinder(MovieFinder movieFinder) {

this.movieFinder = movieFinder; }}

Page 17: Spring Framework Introduction

Xml v.s. Annotation

Trend Micro Confidential

<bean id="movieFinder" class="com.sample.MovieFinder"/>

<bean id="simpleMovieLister” class="com.sample.SimpleMovieLister">

<property name="movieFinder"> <ref local="movieFinder"/>

</property></bean>

Page 18: Spring Framework Introduction

Xml v.s. Annotation

Trend Micro Confidential

@Service

public class SimpleMovieLister {

@Resource

private MovieFinder movieFinder;

public void find() {

movieFinder.find();

}

}

Page 19: Spring Framework Introduction

Xml v.s. Annotation

Trend Micro Confidential

• stereotype annotations• @Component• @Service• @Controller• @Repository

Controller Service Repository

Page 20: Spring Framework Introduction

SpEL

Trend Micro Confidential

• Literal expressions• Properties, Arrays, Lists, Maps, Indexers• Methods• Operators• Assignment• Types• Constructors• Variables• User defined functions• Ternary Operator• Elvis Operator• Safe Navigation operator• Collection Selection• Collection Projection• Expression templating

Page 21: Spring Framework Introduction

Testing

Trend Micro Confidential

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = { "classpath:appContext_core.xml",

"classpath:appContext_index.xml”})public abstract class AbstractTestCase {

}

Page 22: Spring Framework Introduction

Testing

Trend Micro Confidential

• Spring-specific annotations–@TransactionConfiguration–@BeforeTransaction–@AfterTransaction–@IfProfileValue–@ExpectedException–@Timed–@Repeat

Page 23: Spring Framework Introduction

CXF

Trend Micro Confidential

• JAX-WS Support–SOAP 1.1, 1.2

• RESTful services–JSON & XML support

• WS-* Support–WS-Addressing, WS-Policy, WS-ReliableMessaging

and WS-Security

• Spring Integration• Bus

–Fast Infoset

Page 24: Spring Framework Introduction

CXF

Trend Micro Confidential

• RESTful services–JAX-RS–JAX-WS Provider and Dispatch–HTTP Binding(deprecated)

Page 25: Spring Framework Introduction

CXF

Trend Micro Confidential

• Parameters–@PathParam–@QueryParam–@HttpHeader–@MatrixParam–@FormParam–@CookieParam–PathSegment

Page 26: Spring Framework Introduction

Reference

Trend Micro Confidential

• http://caterpillar.onlyfun.net/Gossip/• http://www.springsource.org/• http://cxf.apache.org/

Page 27: Spring Framework Introduction

Trend Micro Confidential

THANK YOU!