Что такое findslide.org?

FindSlide.org - это сайт презентаций, докладов, шаблонов в формате PowerPoint.


Для правообладателей

Обратная связь

Email: Нажмите что бы посмотреть 

Яндекс.Метрика

Презентация на тему Spring Framework

Содержание

Spring Frameworkhttp://www.springsource.com/
Spring Framework Spring Frameworkhttp://www.springsource.com/ Spring missionJ2EE should be easier to useIt's best to program to interfaces, SpringSpring Framework is a Java platform that provides comprehensive infrastructure support for Spring components SpringLightweight—Spring is lightweight in terms of both size and overhead. The entire Dependency injectionInversion of Control (IoC)“Hollywood Principle”Don't call me, I'll call you“Container” resolves Non-IoC / Dependency Injection Non-IoC Service Objectpublic class OrderServiceImpl implements IOrderService {	private IOrderDAO orderDAO = new IoC / Dependency Injection IoC Service Objectpublic class OrderServiceImpl implements IOrderService {	private IOrderDAO orderDAO ;	public OrderServiceImpl Example. Printerpackage org.lesson7.bean;public interface IPrinter {	void printMessage();	void setMessage(String valueOf);}package org.lesson7.bean;public class Printer Example. Containerpackage org.lesson7.bean;public class Container {	private IPrinter printer;	private Double value;	public IPrinter getPrinter() Example. applicationContext.xml Example. Launcherpublic class Launcher {	public static void main(String[] args) {		ApplicationContext context = Example. Annotations (1)Step 1:	@Service	public class Printer implements IPrinter { … }	@Service	public class Example. Annotations (2)public static void main(String[] args) {		ApplicationContext context = new ClassPathXmlApplicationContext(							Annotations@Component – common component@Service - service classes@Controller – controller classes@Repository – DAO classes @Required	This annotation simply indicates that the affected bean property must be populated @Autowired1. Field@Autowiredprivate IPrinter printer;2. Constructor@Autowiredpublic Container(IPrinter printer) {	this.printer = printer;}3. Setter@Autowiredpublic void @Autowired (2)4. All beans of specific type	@Autowired	private IPrinter[] printer;5. Well-known @Qualifier	Since autowiring by type may lead to multiple candidates, it is often JSR-250 Annotations	Spring also provides support for Java EE 5 Common Annotations (JSR-250). Bean scopes Spring AOP	Spring AOP (Aspect-oriented programming) framework is used to modularize cross-cutting concerns Spring AOP	In Spring AOP, comes with three very technical terms – Advice, Spring AOP	In Spring AOP, 5 type of advices are supported :Before advice Spring AOPBeans.xml: @Component@Aspectpublic class TraceLogger {	@Pointcut( Spring AOP	@Before(
Слайды презентации

Слайд 2 Spring Framework





http://www.springsource.com/

Spring Frameworkhttp://www.springsource.com/

Слайд 3 Spring mission
J2EE should be easier to use

It's best

Spring missionJ2EE should be easier to useIt's best to program to

to program to interfaces, rather than classes. Spring reduces

the complexity cost of using interfaces to zero.

JavaBeans offer a great way of configuring applications.

OO design is more important than any implementation technology, such as J2EE.

Checked exceptions are overused in Java. A framework shouldn't force you to catch exceptions you're unlikely to be able to recover from.

Testability is essential, and a framework such as Spring should help make your code easier to test.





Слайд 4 Spring
Spring Framework is a Java platform that provides

SpringSpring Framework is a Java platform that provides comprehensive infrastructure support

comprehensive infrastructure support for developing Java applications. Spring handles

the infrastructure so you can focus on your application.

Spring enables you to build applications from “plain old Java objects” (POJOs) and to apply enterprise services non-invasively to POJOs. This capability applies to the Java SE programming model and to full and partial Java EE.


Слайд 5 Spring components

Spring components

Слайд 6 Spring
Lightweight—Spring is lightweight in terms of both size

SpringLightweight—Spring is lightweight in terms of both size and overhead. The

and overhead. The entire Spring framework can be distributed

in a single JAR file that weighs in at just over 1 MB. And the processing overhead required by Spring is negligible. What’s more, Spring is nonintrusive: objects in a Spring-enabled application typically have no dependencies on Spring specific classes.

Inversion of control—Spring promotes loose coupling through a technique known as inversion of control (IoC). When IoC is applied, objects are passively given their dependencies instead of creating or looking for dependent objects for themselves.

Aspect-oriented - Spring comes with rich support for aspect-oriented programming that enables cohesive development by separating application business logic from system services (such as auditing and transaction management). Application objects do what they’re supposed to do—perform business logic—and nothing more. They are not responsible for (or even aware of) other system concerns, such as logging or transactional support.

Container - Spring is a container in the sense that it contains and manages the life cycle and configuration of application objects. You can configure how your each of your beans should be created—either create one single instance of your bean or produce a new instance every time one is needed based on a configurable prototype—and how they should be associated with each other.

Framework - Spring makes it possible to configure and compose complex applications from simpler components. In Spring, application objects are composed declaratively, typically in an XML file. Spring also provides much infrastructure functionality (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.

Слайд 7 Dependency injection
Inversion of Control (IoC)

“Hollywood Principle”
Don't call me,

Dependency injectionInversion of Control (IoC)“Hollywood Principle”Don't call me, I'll call you“Container”

I'll call you

“Container” resolves (injects) dependencies of components by

setting implementation object (push)

As opposed to component instantiating or Service Locator pattern where component locates implementation (pull)

Martin Fowler calls Dependency Injection


Слайд 8 Non-IoC / Dependency Injection

Non-IoC / Dependency Injection

Слайд 9 Non-IoC Service Object

public class OrderServiceImpl implements IOrderService {
private

Non-IoC Service Objectpublic class OrderServiceImpl implements IOrderService {	private IOrderDAO orderDAO =

IOrderDAO orderDAO = new OrderDaoImpl();

public Order saveOrder(Order order) throws

OrderException{
try{
orderDao.saveOrder(order);
}catch(Exception e){
// handle e, rollback transaction, //cleanup, // throw e
}finally{
//Release resources and handle more exceptions
}
}



Слайд 10 IoC / Dependency Injection

IoC / Dependency Injection

Слайд 11 IoC Service Object

public class OrderServiceImpl implements IOrderService {
private

IoC Service Objectpublic class OrderServiceImpl implements IOrderService {	private IOrderDAO orderDAO ;	public

IOrderDAO orderDAO ;

public OrderServiceImpl (IOrderDAO orderDAO) {
this.orderDAO = orderDAO;
}

public

void setOrderDAO (IOrderDAO orderDAO) {
this.orderDAO = orderDAO;
}

public Order saveOrder(Order order) throws OrderException{
try{
orderDao.saveOrder(order);
}catch(Exception e){
// handle e, rollback transaction, //cleanup, // throw e
}finally{
//Release resources and handle more exceptions
}
}



Слайд 12 Example. Printer
package org.lesson7.bean;

public interface IPrinter {
void printMessage();
void setMessage(String

Example. Printerpackage org.lesson7.bean;public interface IPrinter {	void printMessage();	void setMessage(String valueOf);}package org.lesson7.bean;public class

valueOf);
}



package org.lesson7.bean;

public class Printer implements IPrinter {

private String message;

public

void setMessage(String message) {
this.message = message;
}

public void printMessage() {
System.out.println("Your Message : " + message);
}
}

Слайд 13 Example. Container
package org.lesson7.bean;

public class Container {
private IPrinter printer;
private

Example. Containerpackage org.lesson7.bean;public class Container {	private IPrinter printer;	private Double value;	public IPrinter

Double value;

public IPrinter getPrinter() {
return printer;
}

public void setPrinter(IPrinter printer)

{
this.printer = printer;
}

public void set(Double val) {
this.value = val;
}

public void print() {
printer.setMessage(String.valueOf(this.value));
printer.printMessage();
}
}

Слайд 14 Example. applicationContext.xml



Example. applicationContext.xml

class="org.lesson7.bean.Printer">




/>




Слайд 15 Example. Launcher
public class Launcher {
public static void main(String[]

Example. Launcherpublic class Launcher {	public static void main(String[] args) {		ApplicationContext context

args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"beans.xml"});
Printer bean

= context.getBean("printer", Printer.class);
bean.printMessage();

Container container = context.getBean("container", Container.class);
container.set(1234d);
container.print();

System.out.println(bean == container.getPrinter());
}
}

Слайд 16 Example. Annotations (1)
Step 1:
@Service
public class Printer implements IPrinter

Example. Annotations (1)Step 1:	@Service	public class Printer implements IPrinter { … }	@Service	public

{ … }


@Service
public class Container { … }


Step 2.
@Service
public

class Container {

private IPrinter printer;
private Double value;

@Autowired
public void setPrinter(IPrinter printer) {
this.printer = printer;
}


Слайд 17 Example. Annotations (2)
public static void main(String[] args) {
ApplicationContext

Example. Annotations (2)public static void main(String[] args) {		ApplicationContext context = new ClassPathXmlApplicationContext(

context = new ClassPathXmlApplicationContext(
"beans-annot.xml");

Container container = context.getBean("container", Container.class);
container.set(1234d);
container.print();
}


Слайд 18 Annotations
@Component – common component

@Service - service classes

@Controller –

Annotations@Component – common component@Service - service classes@Controller – controller classes@Repository – DAO classes

controller classes

@Repository – DAO classes


Слайд 19 @Required

This annotation simply indicates that the affected bean

@Required	This annotation simply indicates that the affected bean property must be

property must be populated at configuration time: either through

an explicit property value in a bean definition or through autowiring. The container will throw an exception if the affected bean property has not been populated.



public class SimpleMovieLister {
private MovieFinder movieFinder;

@Required
public void setMovieFinder(MovieFinder movieFinder) {
this.movieFinder = movieFinder;
}
}

Слайд 20 @Autowired
1. Field
@Autowired
private IPrinter printer;

2. Constructor
@Autowired
public Container(IPrinter printer) {
this.printer

@Autowired1. Field@Autowiredprivate IPrinter printer;2. Constructor@Autowiredpublic Container(IPrinter printer) {	this.printer = printer;}3. Setter@Autowiredpublic

= printer;
}

3. Setter
@Autowired
public void setPrinter(IPrinter printer) {
this.printer = printer;
}


Слайд 21 @Autowired (2)
4. All beans of specific type
@Autowired
private IPrinter[]

@Autowired (2)4. All beans of specific type	@Autowired	private IPrinter[] printer;5. Well-known

printer;

5. Well-known "resolvable dependencies“
@Autowired
private ApplicationContext context;


Слайд 22 @Qualifier
Since autowiring by type may lead to multiple

@Qualifier	Since autowiring by type may lead to multiple candidates, it is

candidates, it is often necessary to have more control

over the selection process. One way to accomplish this is with Spring's @Qualifier annotation.

@Autowired
@Qualifier("main")
private MovieCatalog movieCatalog;


@Autowired
public void prepare(@Qualifier("main") MovieCatalog movieCatalog,
CustomerPreferenceDao customerPreferenceDao) {
this.movieCatalog = movieCatalog;
this.customerPreferenceDao = customerPreferenceDao;
}

Слайд 23 JSR-250 Annotations
Spring also provides support for Java EE

JSR-250 Annotations	Spring also provides support for Java EE 5 Common Annotations

5 Common Annotations (JSR-250). The supported annotations are:

@Resource
@PostConstruct
@PreDestroy

@Resource(name =

"dataSource")
public void createTemplate(DataSource dataSource) {
this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
}

public class CachingMovieLister {
@PostConstruct
public void populateMovieCache() {… }

@PreDestroy
public void clearMovieCache() {… }
}



Слайд 25 Bean scopes

Bean scopes

Слайд 26 Spring AOP
Spring AOP (Aspect-oriented programming) framework is used

Spring AOP	Spring AOP (Aspect-oriented programming) framework is used to modularize cross-cutting

to modularize cross-cutting concerns in aspects.

Put it simple,

it’s just an interceptor to intercept some processes, for example, when a method is execute, Spring AOP can hijack the executing method, and add extra functionality before or after the method execution.

Слайд 27 Spring AOP
In Spring AOP, comes with three very

Spring AOP	In Spring AOP, comes with three very technical terms –

technical terms – Advice, Pointcut, Advisor:

Advice – Indicate the

action to take either before or after the method execution.

Pointcut – Indicate which method should be intercept, by method name or regular expression pattern.

Advisor – Group ‘Advice’ and ‘Pointcut’ into a single unit, and pass it to a proxy factory object.

Слайд 28 Spring AOP
In Spring AOP, 5 type of advices

Spring AOP	In Spring AOP, 5 type of advices are supported :Before

are supported :

Before advice – Run before the method

execution

After returning advice – Run after the method returns a result

After throwing advice – Run after the method throws an exception

After (finally) advice – Run after normal or exceptional return

Around advice – Run around the method execution, combine all three advices above.

Слайд 29 Spring AOP
Beans.xml:


@Component
@Aspect
public class TraceLogger {
@Pointcut("execution(* org.lesson7.bean.*.print(..))")
public

Spring AOPBeans.xml: @Component@Aspectpublic class TraceLogger {	@Pointcut(

void log() {
}

@Around("log()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature

signature = (MethodSignature) pjp.getSignature();
Method method = signature.getMethod();
long start = System.currentTimeMillis();
System.out.println("Going to call the method: " + method.getName());

Object output = pjp.proceed();

System.out.println("Method execution completed.");
long elapsedTime = System.currentTimeMillis() - start;
System.out.println("Method execution time: " + elapsedTime
+ " milliseconds.");
return output;
}

  • Имя файла: spring-framework.pptx
  • Количество просмотров: 156
  • Количество скачиваний: 0