Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intermediate Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.

Similar presentations


Presentation on theme: "Intermediate Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic."— Presentation transcript:

1 Intermediate Spring Matt Wheeler

2 Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic Java and XML skills – Installed LdsTech IDE (or other equivalent – good luck there ;)

3 Overview Bean lifecycle Xml Configuration Extensions (namespace handlers) Lifecycle hooks JSR 250 Bean post processors Spring Annotations JSR 330 Annotations (@Inject, @Named)

4 Review Last time we went over – Bean definitions – Dependency Injection (DI) and Inversion of Control (IoC) – Application context – Bean scopes

5 Review ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); SomeBean someBean = context.getBean(SomeBean.class); someBean.callMethod(); Bean definition (beans.xml) Application Context

6 Spring Bean Lifecycle 1. Create bean definitions (from xml or annotations, or, …) 2. Instantiate beans using the definitions 3. Set bean dependencies (values and bean references) on the newly instantiated beans 4. Initialization 5. Deliver bean to requester for use 6. On container shutdown call destruction callback method

7 Xml Configuration Extension Also called namespace handlers Shorten bean definition configuration Provide easily reusable definitions Self documenting More readable

8 Spring Xml Configuration Extensions SchemaDescription / Documentation utilCreate non-anonymous collection types that can be referenced by id http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html#xsd-config-body-schemas-util jeeElements such as jndi support / ejb shortcuts http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html#xsd-config-body-schemas-jee langExpose beans written in another language like JRuby or Groovy http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html#xsd-config-body-schemas-lang jmsDeal with configuring JMS-related beans http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html# xsd-config-body-schemas-jms txTransaction support http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html# xsd-config-body-schemas-tx

9 Xml Configuration Extensions (cont.) SchemaDescirption / Documentation aopHelpers for Spring’s aspect oriented programming mechanisms http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html# xsd-config-body-schemas-aop contextConfiguration relation to the application context plumbing http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html# xsd-config-body-schemas-context toolsConfiguration for adding tooling specific meta-data http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/xsd-config.html# xsd-config-body-schemas-tool securityProvides elements for web security configuration http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns- config.html mvcProvides interceptors, view-conroller, ….. http://static.springsource.org/spring/docs/3.0.x/spring-framework- reference/html/mvc.html#mvc-config

10 Example You have options Or

11 Wait that’s not all And this

12 Another Example Let us utilize a namespace handler <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> abc def ghi jkl abc def ghi jkl

13 Xml Configuration Extension architecture Pieces of namespace handlers Create an xml schema that describes allowable elements Write a namespace handler Code a BeanDefinitionParser – Parses the defined xml and adds any necessary beans into the configuration

14 For Example Bottom line – Namespace handlers are backed by code The code supplements bean configuration and is a lot more than meets the eye Add a parser example here

15 DEMO

16 Lab 3: Bean Scopes https://tech.lds.org/wiki/Introduction_to_Spring#L ab_3_Bean_Scopes

17 Credit where credit is due http://springsource.org Spring Recipies 2 nd Edition (Gary Mak, Josh Long and Daniel Rubio)

18 Dedication Mike Youngstrom and Bruce Campbell for their undying love and support through this process – And for reviewing and offering suggestions And for Spencer Uresk and Mike Heath for the inspiration And a special thanks to the rabbit farm who made this all possible


Download ppt "Intermediate Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic."

Similar presentations


Ads by Google