Spring Fling Phillip Warner
Spring Framework ● Dependency Injection (DI) Framework – “Inversion of Control” ● Facilitates Good Programming Practices ● Facilitates Testing ● Unobtrusive ● Simplifies J2EE/Java EE
Goals ● Let's see some code – Code examples ● Deployment through Spring configuration – XML – Spring configuration examples ● Interesting potential? – What might you do with Spring?
Example 1 – StdoutPrinter ● StdoutPrinter.java – prints to STDOUT ● spring-config.xml – Spring configuration (by setter) ● SpringLoader.java – Spring container Loader ● spring-config-constructor.xml – Spring configuration example (by constructor)
Example 2 – SimpleCalculator ● Operator.java – interface for defining operations ● Add.java, Subtract.java implementations of Operator interface ● Calculator.java – Calculator interface ● SimpleCalculator.java – Calculator implementation. ● SpringLoader.java and AutoSpringLoader.java – Two ways to run the code
Example – VOEvent ● What is VOEvent? – IVOA standard for building and sending XML-based event notices (e.g., SNe, g-ray Bursts, Moving objects) – VOEvent is a broker developed by NOAO ● Provides event publishing, persistence, classification ● Provides event subscription mechanism
Example – VOEvent ● Basic configuration for: – Server/broker ● Publishing, persistence, classification, relay (sending events), and subscription service – Client (author) ● Author events for publication – Client (subscriber) ● Subscription to TCP-based event streams
VOEvent – Classification ● Rules-based ● Spring-configured – For initial implementation—before a database backend and supporting services are provided
VOEvent – Classification (2)
VOEvent – Classification (3)
VOEvent – Classification (4)
Example – Dynamic Workflows
Example – Dynamic Workflows (2)
Spring – Other Features ● Autowiring – Automatic dependency injection ● byType, byName, constructor, autodetect ● Bean scopes – singleton (default), prototype – request, session, global-session (web) – custom
Spring – Other Features ● Annotation-based – Used with auto-wiring, e.g., – tell Spring where the dependency should be injected – (JSR-250) resource injection a la Java EE 5 and (JSR-250) – could be used in legacy or code-based resource allocation – See for more details
Spring – Schema-based Configuration ● – Provides for static definition of: ● Configuration (properties, etc.) ● Collections ● constants – simplifies defining static information – alternative? ● define a bean for each set of information
Spring – Schema-based Configuration ● – Provides for configuration of some Java Enterprise features ● JNDI lookup ● EJB lookup ● – Provides for JMS support ● – Support for Spring's declarative TX management
Spring – Schema-based Configuration ● – Support for AOP (Spring-based) ● – Further support for context configuration ● Spring context, e.g., ApplicationContext ● – Provides support for dynamic languages ● Currently JRuby, Groovy, BSH – Provides support for inlining code
Spring Projects
And so on... For more details, see: