SlideShare a Scribd company logo
1 of 24
Download to read offline
Spring Framework
     Christoph Pickl
agenda
1. short introduction
2. basic declaration
3. medieval times
4. advanced features
5. demo
short introduction
common tool stack

   Log4j            Maven


             Code
Spring              Checkstyle


 Hibernate          JUnit
Spring is a leightweight inversion of control
   and aspect oriented container framework



Spring makes developing J2EE application easier
                 and more fun!
mission statement
•   “J2EE should be easier to use”

•   “it is best to program to interfaces, rather than classes [...]”

•   “JavaBeans offer a great way of configuring applications”

•   “OO is more important than any implementation technology [...]”

•   “checked exceptions are overused in Java [...]”

•   “testability is essential [...]”


                       http://www.springframework.org/about
container age

• heavy (EJB) vs lightweight container (Spring)
• born as alternative to Java EE
• POJO development
• focuses on server development
• no compile dependency on the framework
         http://martinfowler.com/articles/injection.html
basic declaration
  http://de.wikipedia.org/wiki/MenschenwĂźrde
initial setup
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<!-- <!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot;
     quot;http://www.springframework.org/dtd/spring-beans.dtdquot;> -->
<beans
  xmlns=quot;http://www.springframework.org/schema/beansquot;
  xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
  xsi:schemaLocation=quot;http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.0.xsdquot;
  >

  <!-- define your beans here -->

</beans>



       http://static.springframework.org/spring/docs/2.0.x/reference/xsd-cong.html
declare some beans
<!-- this is our first (singleton) bean -->
<bean id=”myDao” class=”jsug.MyDao” />

<bean id=”myCtrl1” class=”jsug.MyController1”>
    <!-- invokes MyController1.setDao(MyDao) -->
    <property name=”dao”>
        <ref bean=”myDao” />
    </property>
</bean>

<!-- share same dao in second controller -->
<bean id=”myCtrl2” class=”jsug.MyController2”>
    <property name=”dao”>
        <ref bean=”myDao” />
    </property>
</bean>
declare easy beans
<!-- reusable string bean -->
<bean id=”SQL_CREATE” class=”java.lang.String”>
    <constructor-arg>
        <value>
            CREATE TABLE myTable ( ... );
        </value>
    </constructor-arg>
</bean>

<!-- pass some string values -->
<bean id=”somePerson” class=”jsug.Person”>
    <property name=”firstName” value=”Christoph” />
    <property name=”lastName” value=”Pickl” />
</bean>
declare more beans
<!-- pass a list of beans -->
<bean id=”someContainer” class=”jsug.SomeContainer”>
    <property name=”modules”>
        <list>
            <ref bean=”module1” />
            <ref bean=”module2” />
        </list>
    </property>
</bean>
<!-- or even a map -->
<bean id=”someOtherContainer” class=”jsug.SomeOtherContainer”>
    <property name=”mailMap”>
        <map>
            <entry key=”cpickl” value=”cpickl@heim.at” />
            <entry key=”fmotlik” value=”fmotlik@heim.at” />
        </map>
    </property>
</bean>
medieval times
early beginning
import   org.springframework.beans.factory.BeanFactory;
import   org.springframework.beans.factory.xml.XmlBeanFactory;
import   org.springframework.core.io.ClassPathResource;
import   org.springframework.core.io.Resource;

public class App { // implements InitializingBean
	 public static void main(String[] args) {
	 	 Resource beanResource =
	 	 	 new ClassPathResource(quot;/beans.xmlquot;);
//		 	 new FileSystemResource(quot;/my/app/beans.xmlquot;);
		
	 	 BeanFactory beanFactory = new XmlBeanFactory(beanResource);
		
	 	 IBean bean = (IBean) beanFactory.getBean(quot;myBeanIdquot;);
	 	 bean.doSomeMethod();
	}
}



             http://www.ociweb.com/mark/programming/SpringIOC.html
~annotation approach
public class App {
	 private SomeBean someBean;
	 /**
	   * @Bean(quot;myBeanIdquot;)
	   */
	 public void setSomeBean(SomeBean someBean) {
	 	 this.someBean = someBean;
	}
}

/**
  * @BeanId(quot;myBeanIdquot;)
  * @BeanScope(quot;singletonquot;)
  */
public class SomeBean {
	 // ...
}
today
// single code dependency to spring throughout our whole application
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
	 public static void main(String[] args) {
	 	 String[] beanDefinitions = { quot;/beans.xmlquot; };
	 	 new ClassPathXmlApplicationContext(beanDefinitions);
	}
	
	 public App() {
	 	 // spring will invoke this constructor for us
	}
	 public void init() {
	 	 // and spring will also invoke this initialize method for us
	}
}
evolution
• first attempt: BeanFactory
 •   direct code dependency :(

• second attempt: Annotations
 •   yet code is polluted

• third attempt: Injection only
 •   complete transparent usage
advanced features
constant injection
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<beans xmlns=quot;http://www.springframework.org/schema/beansquot;
  xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
  xmlns:util=quot;http://www.springframework.org/schema/utilquot;
  xsi:schemaLocation=quot;
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsdquot;>

  <bean id=”myBean” class=”jsug.MyBean”>
    <property name=”someProperty”>
      <util:constant static-field=”jsuga.Constants.MY_CONSTANT” />
    </property
  </bean>

</beans>
init methods
<bean id=”myBean” class=”jsug.MyBean” init-method=”init”>
    <constructor-arg index=”0” value=”someString” />
    <constructor-arg index=”1” ref=”someOtherBean” />
    <property name=”firstName” value=”Christoph” />
</bean>
public class MyBean {
	   private final String someString;
	   private String firstName;

	   // #1 first of all, the bean will be created with proper constructor args
	   public MyBean(String someString, Bean b) { this.someString = someString; }

	   // #2 afterwards, all properties will be set via setter methods
	   public void setFirstName(String firstName) { this.firstName = firstName; }

	   // #3 finally, the initialize method will get invoked
	   public void init() { /* initialize bean in here */ }
}
prototyping
<!-- share the same dao among all students/persons -->
<bean id=quot;daoquot; class=quot;jsuga.DaoImplquot; scope=quot;singletonquot; />

<!-- student implements the IPerson interface -->
<bean id=quot;studentquot; class=quot;jsuga.Studentquot; scope=quot;prototypequot;>
    <constructor-arg ref=quot;daoquot; />
</bean>

<!-- the factory will create (any) persons for us -->
<bean id=quot;personFactoryquot; class=quot;jsuga.PersonFactoryquot;>
    <lookup-method name=quot;newPersonquot; bean=quot;studentquot; />
</bean>


             ... to be continued ...
demo
Framework
       Web Flow
     Web Services
    Security (Acegi)
Dynamic Modules (OSGi)
      Integration
          IDE
      JavaCong
      Rich Client
           ...

http://www.springframework.org/projects
further reading
• Spring official Website
  http://www.springframework.org/




• Spring Reference Documentation
  http://static.springframework.org/spring/docs/2.5.5/spring-reference.pdf




• Spring 2.5 on the Way to 3.0
  http://www.parleys.com/display/PARLEYS/Home#talk=19759132;title=Spring%202.5%20on%20the%20Way%20to%203.0;slide=1

More Related Content

What's hot

How do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML TricksHow do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML Tricks
Compare Infobase Limited
 
Secure Ftp Java Style Rev004
Secure Ftp  Java Style Rev004Secure Ftp  Java Style Rev004
Secure Ftp Java Style Rev004
Rich Helton
 
Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...
Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...
Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...
Peter Martin
 
Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2
Byrne Reese
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
C#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalC#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 Final
Rich Helton
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
bhochhi
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
Rich Helton
 

What's hot (20)

How do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML TricksHow do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML Tricks
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
 
Secure Ftp Java Style Rev004
Secure Ftp  Java Style Rev004Secure Ftp  Java Style Rev004
Secure Ftp Java Style Rev004
 
Fast by Default
Fast by DefaultFast by Default
Fast by Default
 
Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...
Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...
Developing a Joomla 3.x Component using RAD FOF- Part 1: Back-end - Joomladay...
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profit
 
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...
Desenvolvendo uma aplicação híbrida para Android e IOs utilizando Ionic, aces...
 
Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2
 
Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014
Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014
Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014
 
Workshop-Build e deploy avançado com Openshift e Kubernetes
Workshop-Build e deploy avançado com Openshift e KubernetesWorkshop-Build e deploy avançado com Openshift e Kubernetes
Workshop-Build e deploy avançado com Openshift e Kubernetes
 
C#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalC#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 Final
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
[PyConZA 2017] Web Scraping: Unleash your Internet Viking
[PyConZA 2017] Web Scraping: Unleash your Internet Viking[PyConZA 2017] Web Scraping: Unleash your Internet Viking
[PyConZA 2017] Web Scraping: Unleash your Internet Viking
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Faq cruise control
Faq cruise controlFaq cruise control
Faq cruise control
 
An intro to the JAMStack and Eleventy
An intro to the JAMStack and EleventyAn intro to the JAMStack and Eleventy
An intro to the JAMStack and Eleventy
 

Similar to JSUG - Spring by Christoph Pickl

Spring 2.0
Spring 2.0Spring 2.0
Spring 2.0
goutham v
 
Spring 2.0
Spring 2.0Spring 2.0
Spring 2.0
gouthamrv
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
elliando dias
 
Os Johnson
Os JohnsonOs Johnson
Os Johnson
oscon2007
 
Ext 0523
Ext 0523Ext 0523
Ext 0523
littlebtc
 
Uma introdução ao framework Spring
Uma introdução ao framework SpringUma introdução ao framework Spring
Uma introdução ao framework Spring
elliando dias
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
wiradikusuma
 

Similar to JSUG - Spring by Christoph Pickl (20)

Spring 2.0
Spring 2.0Spring 2.0
Spring 2.0
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
 
Spring 2.0
Spring 2.0Spring 2.0
Spring 2.0
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Jsp
JspJsp
Jsp
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
 
สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1
 
Using Maven2
Using Maven2Using Maven2
Using Maven2
 
Os Johnson
Os JohnsonOs Johnson
Os Johnson
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
Ext 0523
Ext 0523Ext 0523
Ext 0523
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
Uma introdução ao framework Spring
Uma introdução ao framework SpringUma introdução ao framework Spring
Uma introdução ao framework Spring
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 

More from Christoph Pickl

More from Christoph Pickl (20)

JSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph PicklJSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph Pickl
 
JSUG - Layouting TeX documents with the Memoir class
JSUG - Layouting TeX documents with the Memoir classJSUG - Layouting TeX documents with the Memoir class
JSUG - Layouting TeX documents with the Memoir class
 
JSUG - Cocoon3 Student Project Idea by Reinhard Poetz and Steven Dolg
JSUG - Cocoon3 Student Project Idea by Reinhard Poetz and Steven DolgJSUG - Cocoon3 Student Project Idea by Reinhard Poetz and Steven Dolg
JSUG - Cocoon3 Student Project Idea by Reinhard Poetz and Steven Dolg
 
JSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph PicklJSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph Pickl
 
JSUG - TeX, LaTeX und der Rest by Norbert Preining
JSUG - TeX, LaTeX und der Rest by Norbert PreiningJSUG - TeX, LaTeX und der Rest by Norbert Preining
JSUG - TeX, LaTeX und der Rest by Norbert Preining
 
JSUG - TeX Day by Christoph Pickl
JSUG - TeX Day by Christoph PicklJSUG - TeX Day by Christoph Pickl
JSUG - TeX Day by Christoph Pickl
 
JSUG - The Sound of Shopping by Christoph Pickl
JSUG - The Sound of Shopping by Christoph PicklJSUG - The Sound of Shopping by Christoph Pickl
JSUG - The Sound of Shopping by Christoph Pickl
 
JSUG - Tim aka EPROG2 by Martin Schuerrer
JSUG - Tim aka EPROG2 by Martin SchuerrerJSUG - Tim aka EPROG2 by Martin Schuerrer
JSUG - Tim aka EPROG2 by Martin Schuerrer
 
JSUG - Java Service Enabler by Andreas Hubmer
JSUG - Java Service Enabler by Andreas HubmerJSUG - Java Service Enabler by Andreas Hubmer
JSUG - Java Service Enabler by Andreas Hubmer
 
JSUG - Hoppla by Florian Motlik and Petar Petrov
JSUG - Hoppla by Florian Motlik and Petar PetrovJSUG - Hoppla by Florian Motlik and Petar Petrov
JSUG - Hoppla by Florian Motlik and Petar Petrov
 
JSUG - Google Web Toolkit by Hans Sowa
JSUG - Google Web Toolkit by Hans SowaJSUG - Google Web Toolkit by Hans Sowa
JSUG - Google Web Toolkit by Hans Sowa
 
JSUG - TU Wien Cocoon Project by Andreas Pieber
JSUG - TU Wien Cocoon Project by Andreas PieberJSUG - TU Wien Cocoon Project by Andreas Pieber
JSUG - TU Wien Cocoon Project by Andreas Pieber
 
JSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas LangJSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas Lang
 
JSUG - LaTeX Introduction by Christoph Pickl
JSUG - LaTeX Introduction by Christoph PicklJSUG - LaTeX Introduction by Christoph Pickl
JSUG - LaTeX Introduction by Christoph Pickl
 
JSUG - OSGi by Michael Greifeneder
JSUG - OSGi by Michael GreifenederJSUG - OSGi by Michael Greifeneder
JSUG - OSGi by Michael Greifeneder
 
JSUG - Filthy Flex by Christoph Pickl
JSUG - Filthy Flex by Christoph PicklJSUG - Filthy Flex by Christoph Pickl
JSUG - Filthy Flex by Christoph Pickl
 
JSUG - Seam by Florian Motlik
JSUG - Seam by Florian MotlikJSUG - Seam by Florian Motlik
JSUG - Seam by Florian Motlik
 
JSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan ZarnikovJSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan Zarnikov
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph Pickl
 
JSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklJSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph Pickl
 

Recently uploaded

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

JSUG - Spring by Christoph Pickl

  • 1. Spring Framework Christoph Pickl
  • 2. agenda 1. short introduction 2. basic declaration 3. medieval times 4. advanced features 5. demo
  • 4. common tool stack Log4j Maven Code Spring Checkstyle Hibernate JUnit
  • 5. Spring is a leightweight inversion of control and aspect oriented container framework Spring makes developing J2EE application easier and more fun!
  • 6. mission statement • “J2EE should be easier to use” • “it is best to program to interfaces, rather than classes [...]” • “JavaBeans offer a great way of conguring applications” • “OO is more important than any implementation technology [...]” • “checked exceptions are overused in Java [...]” • “testability is essential [...]” http://www.springframework.org/about
  • 7. container age • heavy (EJB) vs lightweight container (Spring) • born as alternative to Java EE • POJO development • focuses on server development • no compile dependency on the framework http://martinfowler.com/articles/injection.html
  • 8. basic declaration http://de.wikipedia.org/wiki/MenschenwĂźrde
  • 9. initial setup <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <!-- <!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;http://www.springframework.org/dtd/spring-beans.dtdquot;> --> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation=quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsdquot; > <!-- define your beans here --> </beans> http://static.springframework.org/spring/docs/2.0.x/reference/xsd-cong.html
  • 10. declare some beans <!-- this is our first (singleton) bean --> <bean id=”myDao” class=”jsug.MyDao” /> <bean id=”myCtrl1” class=”jsug.MyController1”> <!-- invokes MyController1.setDao(MyDao) --> <property name=”dao”> <ref bean=”myDao” /> </property> </bean> <!-- share same dao in second controller --> <bean id=”myCtrl2” class=”jsug.MyController2”> <property name=”dao”> <ref bean=”myDao” /> </property> </bean>
  • 11. declare easy beans <!-- reusable string bean --> <bean id=”SQL_CREATE” class=”java.lang.String”> <constructor-arg> <value> CREATE TABLE myTable ( ... ); </value> </constructor-arg> </bean> <!-- pass some string values --> <bean id=”somePerson” class=”jsug.Person”> <property name=”firstName” value=”Christoph” /> <property name=”lastName” value=”Pickl” /> </bean>
  • 12. declare more beans <!-- pass a list of beans --> <bean id=”someContainer” class=”jsug.SomeContainer”> <property name=”modules”> <list> <ref bean=”module1” /> <ref bean=”module2” /> </list> </property> </bean> <!-- or even a map --> <bean id=”someOtherContainer” class=”jsug.SomeOtherContainer”> <property name=”mailMap”> <map> <entry key=”cpickl” value=”cpickl@heim.at” /> <entry key=”fmotlik” value=”fmotlik@heim.at” /> </map> </property> </bean>
  • 14. early beginning import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; public class App { // implements InitializingBean public static void main(String[] args) { Resource beanResource = new ClassPathResource(quot;/beans.xmlquot;); // new FileSystemResource(quot;/my/app/beans.xmlquot;); BeanFactory beanFactory = new XmlBeanFactory(beanResource); IBean bean = (IBean) beanFactory.getBean(quot;myBeanIdquot;); bean.doSomeMethod(); } } http://www.ociweb.com/mark/programming/SpringIOC.html
  • 15. ~annotation approach public class App { private SomeBean someBean; /** * @Bean(quot;myBeanIdquot;) */ public void setSomeBean(SomeBean someBean) { this.someBean = someBean; } } /** * @BeanId(quot;myBeanIdquot;) * @BeanScope(quot;singletonquot;) */ public class SomeBean { // ... }
  • 16. today // single code dependency to spring throughout our whole application import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { public static void main(String[] args) { String[] beanDefinitions = { quot;/beans.xmlquot; }; new ClassPathXmlApplicationContext(beanDefinitions); } public App() { // spring will invoke this constructor for us } public void init() { // and spring will also invoke this initialize method for us } }
  • 17. evolution • rst attempt: BeanFactory • direct code dependency :( • second attempt: Annotations • yet code is polluted • third attempt: Injection only • complete transparent usage
  • 19. constant injection <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:util=quot;http://www.springframework.org/schema/utilquot; xsi:schemaLocation=quot; http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsdquot;> <bean id=”myBean” class=”jsug.MyBean”> <property name=”someProperty”> <util:constant static-field=”jsuga.Constants.MY_CONSTANT” /> </property </bean> </beans>
  • 20. init methods <bean id=”myBean” class=”jsug.MyBean” init-method=”init”> <constructor-arg index=”0” value=”someString” /> <constructor-arg index=”1” ref=”someOtherBean” /> <property name=”firstName” value=”Christoph” /> </bean> public class MyBean { private final String someString; private String firstName; // #1 first of all, the bean will be created with proper constructor args public MyBean(String someString, Bean b) { this.someString = someString; } // #2 afterwards, all properties will be set via setter methods public void setFirstName(String firstName) { this.firstName = firstName; } // #3 finally, the initialize method will get invoked public void init() { /* initialize bean in here */ } }
  • 21. prototyping <!-- share the same dao among all students/persons --> <bean id=quot;daoquot; class=quot;jsuga.DaoImplquot; scope=quot;singletonquot; /> <!-- student implements the IPerson interface --> <bean id=quot;studentquot; class=quot;jsuga.Studentquot; scope=quot;prototypequot;> <constructor-arg ref=quot;daoquot; /> </bean> <!-- the factory will create (any) persons for us --> <bean id=quot;personFactoryquot; class=quot;jsuga.PersonFactoryquot;> <lookup-method name=quot;newPersonquot; bean=quot;studentquot; /> </bean> ... to be continued ...
  • 22. demo
  • 23. Framework Web Flow Web Services Security (Acegi) Dynamic Modules (OSGi) Integration IDE JavaCong Rich Client ... http://www.springframework.org/projects
  • 24. further reading • Spring ofcial Website http://www.springframework.org/ • Spring Reference Documentation http://static.springframework.org/spring/docs/2.5.5/spring-reference.pdf • Spring 2.5 on the Way to 3.0 http://www.parleys.com/display/PARLEYS/Home#talk=19759132;title=Spring%202.5%20on%20the%20Way%20to%203.0;slide=1