Содержание
- 2. Spring Framework http://www.springsource.com/
- 3. Spring mission J2EE should be easier to use It's best to program to interfaces, rather than
- 4. Spring Spring Framework is a Java platform that provides comprehensive infrastructure support for developing Java applications.
- 5. Spring components
- 6. Spring Lightweight—Spring is lightweight in terms of both size and overhead. The entire Spring framework can
- 7. Dependency injection Inversion of Control (IoC) “Hollywood Principle” Don't call me, I'll call you “Container” resolves
- 8. Non-IoC / Dependency Injection
- 9. Non-IoC Service Object public class OrderServiceImpl implements IOrderService { private IOrderDAO orderDAO = new OrderDaoImpl(); public
- 10. IoC / Dependency Injection
- 11. IoC Service Object public class OrderServiceImpl implements IOrderService { private IOrderDAO orderDAO ; public OrderServiceImpl (IOrderDAO
- 12. Example. Printer package org.lesson7.bean; public interface IPrinter { void printMessage(); void setMessage(String valueOf); } package org.lesson7.bean;
- 13. Example. Container package org.lesson7.bean; public class Container { private IPrinter printer; private Double value; public IPrinter
- 14. Example. applicationContext.xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
- 15. Example. Launcher public class Launcher { public static void main(String[] args) { ApplicationContext context = new
- 16. Example. Annotations (1) Step 1: @Service public class Printer implements IPrinter { … } @Service public
- 17. Example. Annotations (2) public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( "beans-annot.xml"); Container
- 18. Annotations @Component – common component @Service - service classes @Controller – controller classes @Repository – DAO
- 19. @Required This annotation simply indicates that the affected bean property must be populated at configuration time:
- 20. @Autowired 1. Field @Autowired private IPrinter printer; 2. Constructor @Autowired public Container(IPrinter printer) { this.printer =
- 21. @Autowired (2) 4. All beans of specific type @Autowired private IPrinter[] printer; 5. Well-known "resolvable dependencies“
- 22. @Qualifier Since autowiring by type may lead to multiple candidates, it is often necessary to have
- 23. JSR-250 Annotations Spring also provides support for Java EE 5 Common Annotations (JSR-250). The supported annotations
- 25. Bean scopes
- 26. Spring AOP Spring AOP (Aspect-oriented programming) framework is used to modularize cross-cutting concerns in aspects. Put
- 27. Spring AOP In Spring AOP, comes with three very technical terms – Advice, Pointcut, Advisor: Advice
- 28. Spring AOP In Spring AOP, 5 type of advices are supported : Before advice – Run
- 29. Spring AOP Beans.xml: @Component @Aspect public class TraceLogger { @Pointcut("execution(* org.lesson7.bean.*.print(..))") public void log() { }
- 31. Скачать презентацию