Open Source Enterprise Frameworks Spring Emerged as lightweight alternative to over-engineered “J2EE” Now suite of OSGi modules "Transparent" dependency

  • View
    213

  • Download
    0

Embed Size (px)

Text of Open Source Enterprise Frameworks Spring Emerged as lightweight alternative to over-engineered...

  • Open Source Enterprise FrameworksSpring Emerged as lightweight alternative to over-engineered J2EE Now suite of OSGi modules"Transparent" dependency injection and transaction managementAla carte services

    HibernateORM ("Object Relational Mapping" for RDBMS to Object mapping)Robust, best-in-class productSophisticated optimization and customization (with learning curve) Reverse engineering of legacy databases

    SiteMesh Like Struts Tiles, but easier to configureOpen Symphony is no more.. You will now be redirected...:

  • High-Level View of FrameworksSpring Key design principles/implementation techniques totally "mainstream"Configuring/using Spring still is not simple Grails manages this...

    Hibernate"Industrial strength"Should compare against commercial products like OracleAs subtle and complex as what it simplifies?-- Grails manages this...

    SiteMeshJust infrastructure, transparently available to use

  • Where to DownloadSpring http://www.springsource.com/download/community Projects:Spring FrameworkSpring GrailsSpring Web Flow

    Hibernatehttp://www.hibernate.org/downloads

    SiteMesh https://github.com/sitemesh/sitemesh2

  • Spring: "Strategic" considerations

    "The original" J2EE alternativeEnterprise apps need Lightweight ContainersKeeps on sprouting new modules (e.g., Batch, Web Flow, LDAP...)OSGI-enabled Spring may be the new WJB4 SpringSource seems to be doing just fineGroovy and GrailsSpringSourceToolsSuiteWaveMaker: WYSIWYG Java studio vFabric tc Server: Enterprise Tomcat serverVMWare vFabric: Develop virtual and cloud applications faster using the Spring framework; deploy to runtime optimized for Spring

  • Spring: part of VMware (http://www.vmware.com/products/)

  • Spring: Key Design Approaches/Features

    POJOs rule! Even EJB3 is built around POJOs.DI (Dependency Injection) instead of Service Locator ("Lookup")"Convention, not configuration"Mechanisms/conventions should not dominate coding effortsJava code annotations can replace external XMLDeclarative services, like transactions"Modular" functionality; as in real OSGiDon't reinvent, provide adapters to reuse "best-of-breed" available solutionsEnable pluggability at core subsystem level (for example, view layer) as well as for add-on features like securitySupport for testing throughout the development life cycle is crucial

  • Spring 3.0 (NOT xml...)Supports specs Java SE 5 and above; Servlet 2.4 and aboveAnnotations not XML!Annotation-based components:@Value expressions, referring to dynamic #{} expressions or static ${} placeholders"Meta-Annotations": custom @MyService annotation for @Service, @Scope("request") and @Transactional(readOnly=true)Standardized dependency injection annotations: @inject, @Autowired, ...Declarative model validation based on constraint annotations @NotNull, @Min(1), ...Enhanced binding and annotation-driven formatting @DateTimeFormat, ...

  • Spring 3.0: SpEL, Portlets, OXM, etc.Spring expression language (SpEL): like Unified EL ( JSTL Expression Language)REST supportURI variable extraction through @PathVariable parametersRestTemplate for Client-side REST supportPortlet 2.0 support @ActionMapping, @RenderMapping, @ResourceMapping, @EventMapping, ...Object/XML Mapping (OXM)From Spring Web ServicesSupport for JAXB 2, Castor, etc.Enhanced scheduling capabilitiesTaskScheduler and Trigger mechanisms @Async and @Scheduled annotations now. T Supports both native and server-managed thread pools

  • Spring3Spring expression language (SpEL):@Componentpublic class CountryAwareLogic {...@Autowiredpublic void setCountry(@Value("#{systemProperties.country}") String country) {this.country=country;}

    }

  • Spring3

    Excellent support for REST by annotatiions@RequestMapping(value = "/reward/{id}", method = GET)public Reward show(@PathVariable("id") long id) { return rewardsAdminService.findReward(id);}

    Support for "web conversations" Should be more like what Seam offersIncorporated current Spring Web Flow project which continue to add more extensions

  • Spring3 ChangesMostly backwards-compatible with Spring2/Spring 2.5Deprecated (but still useable)"Legacy" MVC Controllers like SimpleFormControllerJUnit 3 Spring-customized test classesNew coding should use instead"Legacy" MVC Controllers like SimpleFormControllerJUnit 4 Spring-customized test classesNo single distribution package "spring.jar:"Modular jars were always an alternativeDeploy using Maven2, Ivy, or OSGi (somewhat "bleeding edge")

  • What does Spring contribute to Grails?

    Dependency Injection (solving wiring-at-startup)

    AOP (Aspect Oriented Programming) for automating services

    Spring MVC as Web framework

  • Simple example: Dependency Injection(from http://martinfowler.com/articles/injection.html#InversionOfControl)

    public interface MovieFinder { List findAll();}

    class MovieLister { public Movie[] moviesDirectedBy(String arg) { List allMovies = finder.findAll(); for (Iterator it = allMovies.iterator(); it.hasNext();) { Movie movie = (Movie) it.next(); if (!movie.getDirector().equals(arg)) it.remove(); } return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]); } private MovieFinder finder; public MovieLister() { finder = new ColonDelimitedMovieFinder("movies1.txt"); }

  • What is Dependency Injection?"...For this new breed of containers the inversion is about how they lookup a plugin implementation. In my naive example the lister looked up the finder implementation by directly instantiating it. This stops the finder from being a plugin. The approach that these containers use is to ensure that any user of a plugin follows some convention that allows a separate assembler module to inject the implementation into the lister.

    As a result I think we need a more specific name for this pattern. Inversion of Control is too generic a term, and thus people find it confusing. As a result with a lot of discussion with various IoC advocates we settled on the name Dependency Injection."

    (from http://martinfowler.com/articles/injection.html#InversionOfControl)

  • References on Dependency Injection"A beginners' guide to Dependency Injection": http://www.theserverside.com/tt/articles/article.tss?l=IOCBeginners"DI: What's all the hype (Green Paper)" http://www.manning.com/prasanna/Comparison of IOC (Inversion of Control) containers: http://www.picocontainer.org/comparisons.html

    Tutorials on Spring DI: http://learnspringframework.blogspot.com/2006/10/what-is-ioc.htmlhttp://edudev.hfoss.org/index.php/Spring_Framework_Part_I-The_Context

  • Other frameworks: Dependency Injection/Inversion of ControlGuice http://.code.google.com/p/google-guice

    Picocontainer http://www.picocontainer.org/introduction.html code snippet showing use in web application: http://www.picocontainer.org/web-frameworks.html code snippet showing use from main: http://www.picocontainer.org/component-configuration.html

    http://nanocontainer.codehaus.org/http://www.keelframework.org/index.shtmlhttp://hivemind.apache.org/

  • How does Grails leverage Spring for DI? (1)NOT xml! Just regular Groovy script file that contains Spring DSL

    grails-app/conf/spring/resources.groovy example:import org.springframework.jmx.support.MBeanServerFactoryBeanimport org.springframework.jmx.export.MBeanExporterimport org.hibernate.jmx.StatisticsService

    Beans = { .

    // Hibernate statistics collection. hibernateStats(StatisticsService) { statisticsEnabled = true sessionFactory = ref("sessionFactory") } ...

  • How does Grails leverage Spring for DI? (2) grails-app/conf/spring/resources.groovy example: Beans = { . (con.)

    mbeanServer(MBeanServerFactoryBean) { locateExistingServerIfPossible = true }

    exporter(MBeanExporter) { server = mbeanServer beans = ["org.hibernate:name=statistics": hibernateStats] }}

    (from Smith and Ledbrook, Grails inAction)

  • Comparing Spring xml vs. Grails for DI (1) spring-app.xml:

    scope=prototype autowire=byType init-method=init destroy-method=finish >

    resources.groovy: somebean(x.y.Ex) { b b.scope=prototype b.autowire=byType b.init-method=init b.destroy-method=finish }

  • Comparing Spring xml vs. Grails for DI (2) spring-app.xml:

    1 2 3

    resources.groovy: somelist(x.y.List) { Items =[ 1, 2, 3 ]}

  • Comparing Spring xml vs. Grails for DI (3) spring-app.xml:

    factory-method=create />

    factory-bean=someFactory factory-method=create />

    resources.groovy:

    beanWithStaticFactoryMethod(x.y.ExSrF) { b b.factory-method=create }beanWithFactoryMethod(someFactory:create )

    (from Smith and Ledbrook, Grails inAction)

  • Spring xml can still help in Grails for DI (1)

    ...

  • Spring xml can still help in Grails for DI (2)...

    falsetrue

    true

  • What is Aspect-Oriented Programming?The "next buzzword" after "Objects" and "Components" and "SOA" and ...

    A meta-framework for EJB- (or .NET-) like frameworks which provide infrastructure "services" to applications

    "... clean modularization of crosscutting concerns, such as error checking and handling, synchronization, context-sensitive behavior, performance optimizations, monitoring and logging, debugging support, and multi-object protocols..." (from the AspectJ homepage)

  • What is Aspect-Oriented Programming?O