Spring Framework Introduction

Post on 25-May-2015

963 views 1 download

Tags:

Transcript of Spring Framework Introduction

Copyright 2010 TCloud Computing Inc.

Spring Framework IntroductionAlex Su2010/06/14

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)

IOC

Trend Micro Confidential

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

AOP

Trend Micro Confidential

AOP

Trend Micro Confidential

AOP

Trend Micro Confidential

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

AOP

Trend Micro Confidential

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() { // ... }}

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; }}

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)

Architecture

Trend Micro Confidential

Architecture

Trend Micro Confidential

Architecture

Trend Micro Confidential

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

Architecture

Trend Micro Confidential

Architecture

Trend Micro Confidential

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; }}

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>

Xml v.s. Annotation

Trend Micro Confidential

@Service

public class SimpleMovieLister {

@Resource

private MovieFinder movieFinder;

public void find() {

movieFinder.find();

}

}

Xml v.s. Annotation

Trend Micro Confidential

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

Controller Service Repository

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

Testing

Trend Micro Confidential

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

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

}

Testing

Trend Micro Confidential

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

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

CXF

Trend Micro Confidential

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

CXF

Trend Micro Confidential

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

Reference

Trend Micro Confidential

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

Trend Micro Confidential

THANK YOU!