Скачать презентацию Spring Power to the POJO Introductie Скачать презентацию Spring Power to the POJO Introductie

9bcd1c2408d1a985aa3eec438cc9efae.ppt

  • Количество слайдов: 72

 Spring – Power to the POJO Introductie tot het Spring Framework Lucas Jellema Spring – Power to the POJO Introductie tot het Spring Framework Lucas Jellema Oracle Consulting – Java Professional Community, maandag 29 augustus 2005 Oracle Consulting – Java Professional Community – 29 augustus 2005 1

Agenda Introductie Spring – History, Background Hoe kom je aan nieuwe objecten § Bean. Agenda Introductie Spring – History, Background Hoe kom je aan nieuwe objecten § Bean. Factory en Inversion of Control + Dependency Injection Hoe laat je bestaande objecten naar je pijpen dansen? § Aspect Oriented Programming (AOP) Business Tier & Architectuur Test Driven Development Spring Persistence & Spring DAO Spring Remoting Losse eindjes, conclusies, discussie Workshop Oracle Consulting – Java Professional Community – 29 augustus 2005 2

Where we’ve come from EJB as we know it… § Resembles the original Java. Where we’ve come from EJB as we know it… § Resembles the original Java. Beans specification in name only. § Heavyweight: • • • Requires application server Difficult to unit-test Intrusive (must implement EJB interfaces) § Complex • • Home/Remote/Local. Home interfaces Deployment descriptors § Non-intuitive Oracle Consulting – Java Professional Community – 29 augustus 2005 3

The future of EJB… Spilling the beans… § § EJB 3. 0 will embrace The future of EJB… Spilling the beans… § § EJB 3. 0 will embrace simplicity Based on POJO/POJI (? Well, maybe) Employ dependency injection instead of LDAP Declarative services (transactions, security) will be aspects § Entity beans will be POJOs, persisted via Hibernatelike framework Oracle Consulting – Java Professional Community – 29 augustus 2005 4

The future is NOW! Spring is a lightweight container framework § Build applications based The future is NOW! Spring is a lightweight container framework § Build applications based on POJO/POJI. § Wire beans together using dependency injection. § Declaratively apply transactions and security using aspect. § Integrates cleanly with Hibernate for persistence. EJB 3. 0=Spring + Hibernate + Metadata Oracle Consulting – Java Professional Community – 29 augustus 2005 5

Spring History J 2 EE Design and Development – by Rod Johnson, 2002 § Spring History J 2 EE Design and Development – by Rod Johnson, 2002 § Introducing the i 21 framework First release of Spring: Spring 2004 Spring 1. 2. 4: August 2005 Open Source § Interface 21 – small company with most core committers § Contributions from Oracle and other parties § Spawned many sub-projects Oracle Consulting – Java Professional Community – 29 augustus 2005 6

Power to the POJO Co ns P AO ist e (T nt S em Power to the POJO Co ns P AO ist e (T nt S em e pla rvic te e A Pa bs tte tra rn cti ) on s Io. C (Dependency Injection) Oracle Consulting – Java Professional Community – 29 augustus 2005 7

Spring’s modules Oracle Consulting – Java Professional Community – 29 augustus 2005 8 Spring’s modules Oracle Consulting – Java Professional Community – 29 augustus 2005 8

What’s more… § Remoting support via RMI, JAX-RPC, and Hessian/Burlap § Metadata (ala, JSR-175 What’s more… § Remoting support via RMI, JAX-RPC, and Hessian/Burlap § Metadata (ala, JSR-175 or Commons Attributes) § Persistence via Top. Link, Hibernate, JDO, or i. Batis support § E-mail support § EJB support § JMX Support (Spring 1. 1) § JMS support § Spring Rich Client Platform (Spring 1. 1) § Spring. Net Oracle Consulting – Java Professional Community – 29 augustus 2005 9

Spring is HOT! Oracle Consulting – Java Professional Community – 29 augustus 2005 10 Spring is HOT! Oracle Consulting – Java Professional Community – 29 augustus 2005 10

Many books available J 2 EE without EJB § The starting point Spring Live Many books available J 2 EE without EJB § The starting point Spring Live Pro Spring in Action Professional Spring Development § By The Team Oracle Consulting – Java Professional Community – 29 augustus 2005 11

Spring Home: http: //www. springframework. org Oracle Consulting – Java Professional Community – 29 Spring Home: http: //www. springframework. org Oracle Consulting – Java Professional Community – 29 augustus 2005 12

Core Spring Inversion of Control & Dependency Injection Oracle Consulting – Java Professional Community Core Spring Inversion of Control & Dependency Injection Oracle Consulting – Java Professional Community – 29 augustus 2005 13

Coupling Highly coupled code is… § Hard to test § Hard to maintain § Coupling Highly coupled code is… § Hard to test § Hard to maintain § Exhibits “whack-a-mole” style bugs • Here one pops up, when you solve it, another one appears Uncoupled code is… § Code that doesn’t do anything Coupling is somewhat necessary… § …but should be controlled Oracle Consulting – Java Professional Community – 29 augustus 2005 14

Dependency Injection The “Hollywood Principle”: Don’t call me, I’ll call you. Collaborators aren’t asked Dependency Injection The “Hollywood Principle”: Don’t call me, I’ll call you. Collaborators aren’t asked for…they’re received. Also known as “Dependency Injection”, thanks to Martin Fowler. Oracle Consulting – Java Professional Community – 29 augustus 2005 15

Benefits of Io. C Objects are more cohesive because they are no longer responsible Benefits of Io. C Objects are more cohesive because they are no longer responsible for obtaining their own collaborators. When used with interfaces, code is very loosely coupled. Oracle Consulting – Java Professional Community – 29 augustus 2005 16

Elements of a Spring app Beans § Not EJBs. Actually, not necessarily Java. Beans. Elements of a Spring app Beans § Not EJBs. Actually, not necessarily Java. Beans. Just POJOs Bean wiring § Typically an XML file. A bootstrap class § A class with a main() method. § A servlet. The bootstrap class uses a Bean. Factory (or Io. C Container) to retrieve POJOs § That have been ‘wired’ and ‘dependency injected’ Oracle Consulting – Java Professional Community – 29 augustus 2005 17

Io. C Container in Action Application Class needs POJOs POJO 2 xml POJO 1 Io. C Container in Action Application Class needs POJOs POJO 2 xml POJO 1 Io. C Container POJO 3 pojo 1 pojo 2 get. Bean(“POJO 1”) pojo 3 Application Oracle Consulting – Java Professional Community – 29 augustus 2005 18

Io. C Container in Action Application Class needs POJOs Hrm. Service xml Hrm. Service. Io. C Container in Action Application Class needs POJOs Hrm. Service xml Hrm. Service. Impl Io. C Container employee. Dao get. Bean(“hrm. Service”) Emp. DAO hrm. Service Employee. Jdbc. DAO data. Source. DBDirect Driver. Manager. Data. Source Oracle Consulting – Java Professional Community – 29 augustus 2005 Data. Source Hrm. Client 19

Wiring beans in XML Root elements is <beans> Contains one or more <bean> elements Wiring beans in XML Root elements is Contains one or more elements § id (or name) attribute to identify bean § class attribute to specify class The bean’s ID Oracle Consulting – Java Professional Community – 29 augustus 2005 The bean’s fullyqualified classname 20

Wiring a property Use <property> element § name attribute specifies name of property <beans> Wiring a property Use element § name attribute specifies name of property Maps to a set. Bar() call Oracle Consulting – Java Professional Community – 29 augustus 2005 21

Property values Strings and numbers: <property name=“bar”><value>42</value></property> <property name=“bar”><value>Hello</value></property> Null <property name=“bar”><null/></property> Lists and Property values Strings and numbers: 42 Hello Null Lists and arrays: ABC 123 Oracle Consulting – Java Professional Community – 29 augustus 2005 22

Property values Sets: <property name=“bar”> <set> <value>ABC</value> <value>123</value> </set> </property> Maps: <property name=“bar”> <map> Property values Sets: ABC 123 Maps: ABC 123 Oracle Consulting – Java Professional Community – 29 augustus 2005 23

Property values Property sets: <property name=“bar”> <props> <prop key=“prop 1”>ABC</prop> <prop key=“prop 2”>123</prop> </set> Property values Property sets: ABC 123 Other beans: Oracle Consulting – Java Professional Community – 29 augustus 2005 24

Auto-wiring You can auto-wire… § “by. Name”: Property names are matched to bean names Auto-wiring You can auto-wire… § “by. Name”: Property names are matched to bean names § “by. Type”: Property names are matched to bean types § “constructor”: Pico-like constructor wiring. Like “by. Type” except using constructor. § “autodetect”: Uses reflection to decide whether to use “by. Type” or “constructor” Oracle Consulting – Java Professional Community – 29 augustus 2005 25

Auto-wiring <bean id=“foo” class=“com. habuma. foobar. Foo” autowire=“by. Name”/> <bean id=“foo” class=“com. habuma. foobar. Auto-wiring bar Oracle Consulting – Java Professional Community – 29 augustus 2005 26

Bean. Factory vs. Application. Context A Bean. Factory is the Spring container. § Loads Bean. Factory vs. Application. Context A Bean. Factory is the Spring container. § Loads beans and wires beans together. § Dispenses beans as requested. § Xml. Bean. Factory is the most commonly used. An Application. Context is a Bean. Factory, but adds “framework” features such as: § I 18 N messages § Event notification Oracle Consulting – Java Professional Community – 29 augustus 2005 27

 Io. C Examples Oracle Consulting – Java Professional Community – 29 augustus 2005 Io. C Examples Oracle Consulting – Java Professional Community – 29 augustus 2005 28

Example of a Io. C based programming Oracle Consulting – Java Professional Community – Example of a Io. C based programming Oracle Consulting – Java Professional Community – 29 augustus 2005 29

Core Spring Aspect Oriented Programming AOP – a programming technique that promotes separation of Core Spring Aspect Oriented Programming AOP – a programming technique that promotes separation of concerns within a software system Recurring – often infrastructural – concerns can easily be duplicated in many objects § Security § Transaction Management § Logging § Profiling AOP suggests separation § Concerns are applied at compile or run-time Oracle Consulting – Java Professional Community – 29 augustus 2005 32

AOP in a nutshell Aspect: A modularization of a cross-cutting concern. Implemented in Spring AOP in a nutshell Aspect: A modularization of a cross-cutting concern. Implemented in Spring as Advisors or interceptors Joinpoint: Point during the execution of execution. Advice: Action taken at a particular joinpoint. Pointcut: A set of joinpoints specifying where advice should be applied. Advisor: Fully represents an aspect, including both advice and a pointcut. Introduction: Adding methods or fields to an advised class. Weaving: Assembling aspects into advised objects. Oracle Consulting – Java Professional Community – 29 augustus 2005 33

Without AOP Oracle Consulting – Java Professional Community – 29 augustus 2005 34 Without AOP Oracle Consulting – Java Professional Community – 29 augustus 2005 34

With AOP Oracle Consulting – Java Professional Community – 29 augustus 2005 35 With AOP Oracle Consulting – Java Professional Community – 29 augustus 2005 35

Implementing AOP Compile time – modify the source code during compilation § Requires a Implementing AOP Compile time – modify the source code during compilation § Requires a customized Java Compiler § For example Aspect. J; Spring does not do compile time AOP Run time – byte injection § Change the class when loaded, generating a subclass that contains the aspects § Uses CGLib library Run time – using the JDK 1. 3 Dynamic Proxy § Instead of getting an object instance, the application receives a proxy object § The proxy implements the same interface • • And maybe something else as well Besides, it can intercept and wrap method calls Oracle Consulting – Java Professional Community – 29 augustus 2005 36

Io. C Container hides AOP implementation from POJO consumer Aspect A Proxy invoke() xml Io. C Container hides AOP implementation from POJO consumer Aspect A Proxy invoke() xml target= pojo 1 Impl pojo 1 = proxy ÞTarget intercept or. Names => Aspect. A, Aspect. B Aspect B target Pojo 1 Impl before() implements Io. C Container implements POJO 1 (interface) get. Bean(“POJO 1”) Application Aspect. A Aspect. B Oracle Consulting – Java Professional Community – 29 augustus 2005 37

Different types of Advice Before advice § After returning advice § Calls to advised Different types of Advice Before advice § After returning advice § Calls to advised methods are intercepted after an exception is thrown. Around advice/interception § Calls to advised methods are intercepted after a successful return. After throws advice § Calls to advised methods are intercepted before the method is called. Calls to advised methods are intercepted. Call must be explicitly made to target method. Introduction advice § § Allows a class (or rather its proxy) to implement additional interfaces Calls to methods are intercepted…even when the target bean doesn’t have the method! • Actually, just a special case of around advice Oracle Consulting – Java Professional Community – 29 augustus 2005 38

Creating Advise Create a class that implements one or more of the Spring AOP Creating Advise Create a class that implements one or more of the Spring AOP interfaces § § Method. Interceptor Before. Advice After. Returning. Advice Throws. Advice Implement the interface method § before (Method method, Object[] args) § after. Returning(Object return. Value, Method method, Object[] args) § invoke(Method. Invocation invocation) Oracle Consulting – Java Professional Community – 29 augustus 2005 39

Defining Pointcuts in Spring (specify where to apply which Advice) Programmatically § No Bean. Defining Pointcuts in Spring (specify where to apply which Advice) Programmatically § No Bean. Factory required § Can be used independently of the rest of Spring Declaratively § In the bean container configuration file (application. Context. xml) Oracle Consulting – Java Professional Community – 29 augustus 2005 40

Applications of AOP by Spring itself always in conjunction with Io. C/DI Remoting Support Applications of AOP by Spring itself always in conjunction with Io. C/DI Remoting Support § Proxy references a remote object Transaction Management § Service method is wrapped in around advice that opens and closes the transaction Security JMX § Proxy implements the MBean interfaces for its target object Mock Testing § Tested objects are injected with Mock objects that are dynamically created (made up) Oracle Consulting – Java Professional Community – 29 augustus 2005 41

Future of AOP – according to Rod Johnson Programming Aspects and composing an Application Future of AOP – according to Rod Johnson Programming Aspects and composing an Application from Aspects will become widely accepted § Various orthogonal concerns can be dealt with in parallel § Maintaining a single – cross application concern – is done by maintaining a single aspect § Tool and Runtime support for AOP will further increase Development of IBM Web. Sphere & WSAD is heavily done in an AOP fashion Oracle Consulting – Java Professional Community – 29 augustus 2005 45

Spring’s recommended Application Guidelines and Architecture Program against interfaces § For example Service Interface, Spring’s recommended Application Guidelines and Architecture Program against interfaces § For example Service Interface, DAO Interfaces § Typically no interfaces for Domain Classes No configuration “plumbing” in your classes § Have configuration details injected Domain Classes are used through all tiers § No Struts Action. Forms to wrap domain classes § Controllers use Business Service methods to create or manipulate Domain Objects Practice “Test driven development” Oracle Consulting – Java Professional Community – 29 augustus 2005 46

Spring’s recommended architecture Presentation Tier View Components Generate HTML or PDF Remote Service Exporters Spring’s recommended architecture Presentation Tier View Components Generate HTML or PDF Remote Service Exporters Web Tier Actions Using SOAP, RMI, JAX-RPC etc. (Controllers) Business Tier Business Services Layer Interfaces and Container Managed Implementations Data Tier DAO Interface Layer Interfaces, independent of implementing DAO Technology DAO Implementation layer Retrieves, saves entities using ORM tool or JDBC Oracle Consulting – Java Professional Community – 29 augustus 2005 RDBMS JDBC O/R Mapping Layer Persistent Domain Objects 47

Spring and Test Driven Development Agile Software Engineering methods, such as XP First design Spring and Test Driven Development Agile Software Engineering methods, such as XP First design and develop a test based on interfaces § Before implementing the interfaces § Before starting to resolve a bug Automated Unit Testing for every class in the application § At every stage of development, the test can be rerun! Unit Testing usually based on JUnit § Great integration in Eclipse and JDeveloper 10. 1. 3 (10. 1. 2 is somewhat sparse) Oracle Consulting – Java Professional Community – 29 augustus 2005 48

Spring and Test Driven Development Challenges include § Container Dependencies (Http. Servlet object) § Spring and Test Driven Development Challenges include § Container Dependencies (Http. Servlet object) § Dependencies on external objects (not a unit test) • Especially objects that are hard to configure, e. g. DAO Impl § Dependencies on objects that have not yet been implemented Oracle Consulting – Java Professional Community – 29 augustus 2005 49

Spring support for Test Driven Development When all objects (Service and DAO Impl) are Spring support for Test Driven Development When all objects (Service and DAO Impl) are Spring Beans § They get dependency injected by the container During a test, instead of injecting them with real objects § We can inject them with Mock Objects, that will return the values we specify when called § The real objects do not need to exist • even when they do exist, using mock objects ensures we are performing a true UNIT test Oracle Consulting – Java Professional Community – 29 augustus 2005 50

Unit Testing Hrm. Service. Impl using Mock objects Unit Test Hrm. Service. Test (JUnit Unit Testing Hrm. Service. Impl using Mock objects Unit Test Hrm. Service. Test (JUnit Test. Case) Mock. Employee. DAOImpl Business Tier Hrm. Service. Impl Data Tier Employee. DAO Interfaces, independent of implementing DAO Technology Employee. DAOImpl (does not yet exist) Oracle Consulting – Java Professional Community – 29 augustus 2005 Persistent Domain Objects 51

Testen en Mock. Objects public class Test. Employee. Dao extends Abstract. Dependency. Injection. Spring. Testen en Mock. Objects public class Test. Employee. Dao extends Abstract. Dependency. Injection. Spring. Context. Tests { private Employee. Dao employee. DAO; public void set. Employee. DAO(Employee. Dao employee. DAO) { this. employee. DAO = employee. DAO; } protected String[] get. Config. Locations() { return new String[] {"nl/amis/demo/dao/jdbc/application. Context-jdbc. xml"}; } public void test. Find. Employee. By. Id () { Employee emp = employee. DAO. get. Employee. By. Id(7839); assert. Equals("KING", emp. get. Name()); assert. Equals("PRESIDENT", emp. get. Job()); //. . . } } Oracle Consulting – Java Professional Community – 29 augustus 2005 52

Properly implementing those Mock DAO objects Spring JDBC and Spring DAO Oracle Consulting – Properly implementing those Mock DAO objects Spring JDBC and Spring DAO Oracle Consulting – Java Professional Community – 29 augustus 2005 53

Doelen van Spring JDBC Database acties § SQL (Select en Manipulatie) § Procedural (stored Doelen van Spring JDBC Database acties § SQL (Select en Manipulatie) § Procedural (stored procedure calls) Flexibel § § Externe configuratie van data source Geen Checked Exceptions Out of container testen Database onafhankelijk Gecontroleerd § Exception handling § Connection leaking/connection pooling Productief § Geen herhaling van code (tcftc) § Vereenvoudigen van Transaction Management Oracle Consulting – Java Professional Community – 29 augustus 2005 54

Architectuur Domain Object JNDI Service DAO Oracle Consulting – Java Professional Community – 29 Architectuur Domain Object JNDI Service DAO Oracle Consulting – Java Professional Community – 29 augustus 2005 55

Example import java. sql. *; import javax. sql. *; public class Emp. Dao { Example import java. sql. *; import javax. sql. *; public class Emp. Dao { public List get. All. Employees() { Connection con = null; Prepared. Statement pstmt = null; Result. Set rs = null; List emps = new Array. List(); try { con = get. Connection(); pstmt = con. prepare. Statement ("select * from emp"); rs = pstmt. execute. Query(); while (rs. next()) { Employee e = new Employee(); e. set. Id (rs. get. Long(1)); e. set. Name (rs. get. String(2)); //. . . emps. add(e); } } catch (SQLException e) { // handle exception } finally { try { rs. close(); pstmt. close(); con. close(); } catch (SQLException e 1) { // no action needed } } return emps; } } private Connection get. Connection() throws SQLException { try { Context ic = new Initial. Context(); Data. Source ds = (Data. Source) ic. lookup ("java: comp/env/jdbc/my. Database"); return ds. get. Connection(); } catch (Naming. Exception e) { // handle exception return null; } } Oracle Consulting – Java Professional Community – 29 augustus 2005 private Connection get. Connection() throws SQLException { try { Driver. Manager. register. Driver (new oracle. jdbc. driver. Oracle. Driver()); return Driver. Manager. get. Connection ("jdbc: oracle: thin: @localhost: 1521: orcl“ , "scott", "tiger"); } catch (SQLException sqle) { // handle exception return null; } } 56

Template Pattern Operation largely follows a standard algorithm At certain steps, specialization or customization Template Pattern Operation largely follows a standard algorithm At certain steps, specialization or customization is required Several implementations § Abstract ‘hook’ methods that sub-class may override § Parametrize behaviour and have invoker provide the details • Such as the SQL Query Spring JDBC Templates § Implement all JDBC wiring § Parametrize the query and the result-handling Oracle Consulting – Java Professional Community – 29 augustus 2005 57

Example of Spring JDBC Template public interface emp. Dao { public List get. All. Example of Spring JDBC Template public interface emp. Dao { public List get. All. Employees (); } public class Employee. Jdbc. Dao extends Jdbc. Dao. Support implements Emp. Dao { public List get. All. Employees() { Jdbc. Template jt = get. Jdbc. Template(); return jt. query. For. List (“select * from emp”); } } Oracle Consulting – Java Professional Community – 29 augustus 2005 58

jdbc helper classes Jdbc. Template § query, query. For. List, query. For. Int, query. jdbc helper classes Jdbc. Template § query, query. For. List, query. For. Int, query. For. . § Array. List (per row) of Hash. Maps (column name as key) Row. Mapper Prepared. Statement. Creator/Callback Mapping. SQLQuery . . . Oracle Consulting – Java Professional Community – 29 augustus 2005 59

How can Spring help? Make life easier: DAO Support § JDBC, Hibernate, Toplink, i. How can Spring help? Make life easier: DAO Support § JDBC, Hibernate, Toplink, i. Batis, JDO, javax. persistence (“EJB 3. 0”) , . . . Dependency Injection Jdbc helper classes Exception Handling Mock. Objects Transaction Management Oracle Consulting – Java Professional Community – 29 augustus 2005 60

Spring Architectuur Domain Object DAO Interface XXDAO Support Jdbc. Dao. Support Hibernate. Dao. Support Spring Architectuur Domain Object DAO Interface XXDAO Support Jdbc. Dao. Support Hibernate. Dao. Support Top. Link. Dao. Support. . . Service DAO Application. Context-jdbc Oracle Consulting – Java Professional Community – 29 augustus 2005 61

Exception Handling Runtime. Exception ipv checked SQLException § Data. Access. Exception SQLException Translation § Exception Handling Runtime. Exception ipv checked SQLException § Data. Access. Exception SQLException Translation § § Data. Integrity. Violation. Exception Data. Retrieval. Failure. Exception Cannot. Get. Jdbc. Connection. Exception. . . Oracle Consulting – Java Professional Community – 29 augustus 2005 62

Spring and Web Applications Struts and other Controller Frameworks Struts support § Auto-Load Web. Spring and Web Applications Struts and other Controller Frameworks Struts support § Auto-Load Web. Context (== Bean. Factory) in session § Make Action Classes Spring aware and have them reference the Web. Context § Proxy Action Classes and Dependency Inject them • Register Actions as Spring Beans Similar support for § Web. Work § Tapestry Oracle Consulting – Java Professional Community – 29 augustus 2005 63

Spring and Web Applications Java Server Faces Java Server Faces JSF has managed-beans § Spring and Web Applications Java Server Faces Java Server Faces JSF has managed-beans § Very similar to Spring Beans § Though no support for AOP § And: do you want low level, persistency related configuration details in the faces-config. xml JSF-Spring project offers a JSF variable resolver § It takes bean references in faces-config. xml and tries to resolve them in Spring context files Oracle Consulting – Java Professional Community – 29 augustus 2005 64

Spring and Web Applications Spring MVC Controller Framework Positioned to replace Struts § Better, Spring and Web Applications Spring MVC Controller Framework Positioned to replace Struts § Better, more intuitive, modern architecture § Full benefits from Io. C and AOP Works with (these are all Spring Beans) § Controllers – that process the request, update and prepare the Model; they also return a result, a symbolic indication of the Model. View to proceed to § View. Resolvers – that decide which View to let render § View. Beans – that wrap View Components such as JSP, Velocity Template, Free. Marker page Oracle Consulting – Java Professional Community – 29 augustus 2005 65

Spring MVC Controller Framework Support for various View technologies JSP – using the Spring Spring MVC Controller Framework Support for various View technologies JSP – using the Spring tag-library (very small, primarily use JSTL) Free. Marker Velocity Tiles File Download Excel – using Apache POI PDF – using i. Text XSL-T Jasper. Reports Oracle Consulting – Java Professional Community – 29 augustus 2005 66

Spring Remote Support for distributed applications Spring’s number one concept concerning remote, distributed objects Spring Remote Support for distributed applications Spring’s number one concept concerning remote, distributed objects (take from Martin Fowler): § Do NOT distribute!!! However, in certain circumstances you probably have to § Cross organizational boundaries § Rich Clients § Remote process accessing back-end server Oracle Consulting – Java Professional Community – 29 augustus 2005 67

Spring’s Remote Façade Philosphy Remote access § for example supporting remote clients over RMI Spring’s Remote Façade Philosphy Remote access § for example supporting remote clients over RMI or publishing a Web. Service should be regarded as an alternative presentation layer § no different from an standard Browser oriented HTML interface On well-defined middle tier service interfaces § that are blissfully unaware that they are exposed and consumed remotely Remoting infrastructure – for example Data Transfer Objects – should be added on top of the well defined, OO, fully POJO based service Oracle Consulting – Java Professional Community – 29 augustus 2005 68

Spring support for “remoting” Spring will § Declaratively expose Service interfaces for remote clients Spring support for “remoting” Spring will § Declaratively expose Service interfaces for remote clients § Declaratively expose remote Service interfaces for local clients Support for these protocols: § § § RMI Caucho’s Hessian and Burlap Spring’s own Http. Invoker EJB SOAP (based on JAX-RPC, using AXIS or XFire) Oracle Consulting – Java Professional Community – 29 augustus 2005 69

Exposing Service to remote clients Client. Code Proxy for Service (generated by Bean. Factory) Exposing Service to remote clients Client. Code Proxy for Service (generated by Bean. Factory) Service Interface Spring Exporter Service Implementation Oracle Consulting – Java Professional Community – 29 augustus 2005 70

Spring Exporters Declaratively set up in the configuration file Using a specific protocol Spring Spring Exporters Declaratively set up in the configuration file Using a specific protocol Spring Service Exporter § defines an End Point where the Service can be invoked • typically linked to a port § translates incoming remote calls to local calls • unmarshalling parameter values • marshalling return values and exceptions Spring Exporter often works with Spring Remote Client Oracle Consulting – Java Professional Community – 29 augustus 2005 71

Details from Server and Client side Bean. Configuration files Server Side – Http. Invoker Details from Server and Client side Bean. Configuration files Server Side – Http. Invoker Protocol Exporter Client Side – Http. Invoker Protocol proxy creator Oracle Consulting – Java Professional Community – 29 augustus 2005 72

Extra Features JMX – proxy Spring Beans to register them as MBeans JMS Email Extra Features JMX – proxy Spring Beans to register them as MBeans JMS Email JNDI Scheduling (Quartz) Transaction Management Oracle Consulting – Java Professional Community – 29 augustus 2005 73

Spring and the Oracle Java Technology Stack Spring DAO has Top. Link support § Spring and the Oracle Java Technology Stack Spring DAO has Top. Link support § Since Spring 2005, contributed by Oracle Spring based POJO business service can be registered with ADF Binding Framework § Ideally we can have the registration mechanism honor the Application. Context origin of the Service Object § Question: how does ADF currently instantiate its Business Services? Spring DAO for ADF BC seems pointless § ADF BC is already pretty much wrapped – the API is already fairly high level § The Configurations (bc 4 j. xcfg) provide a level of decoupling and dependency injection § Spring DAO focuses on POJO – ADF BC does not Oracle Consulting – Java Professional Community – 29 augustus 2005 74

Spring and the Oracle Java Technology Stack Spring MVC on ADF BC Business Service Spring and the Oracle Java Technology Stack Spring MVC on ADF BC Business Service could be done § though a lot of the natural benefits are lost UIX could be used with Spring MVC as View technology § losing the Struts ADF Life. Cyle management Shortly ADF Faces can be used with Spring MVC as well Spring Remoting can be used to publish and consume § Somewhat overlapping with JDeveloper Web. Services support Spring AOP could be applied to ADF BC objects § If we can find the right hook – does not seem easy! Oracle Consulting – Java Professional Community – 29 augustus 2005 75

Sub Projects and initiatives around Spring Spring Security Spring IDE (for Eclipse) Spring Rich Sub Projects and initiatives around Spring Spring Security Spring IDE (for Eclipse) Spring Rich Client Spring Modules & Spring Web. Flow Spring Bean. Doc Spring. NET – by Rod Johnson et. al. § Focus on C# JSF-Spring XDoclet – Spring Bean Configuration generator Aurora MVC Framework More support for Persistency OO/R Frameworks § EJB 3. 0… Oracle Consulting – Java Professional Community – 29 augustus 2005 76

Discussion Ik lust eigenlijk nu ook wel een kop koffie… Oracle Consulting – Java Discussion Ik lust eigenlijk nu ook wel een kop koffie… Oracle Consulting – Java Professional Community – 29 augustus 2005 77