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-config.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
      JavaConfig
      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 TricksCompare Infobase Limited
 
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...Peter Martin
 
Secure Ftp Java Style Rev004
Secure Ftp  Java Style Rev004Secure Ftp  Java Style Rev004
Secure Ftp Java Style Rev004Rich 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
 
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 profitBen Limmer
 
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...Juliano Martins
 
Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Byrne Reese
 
Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Byrne Reese
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialYi-Ting Cheng
 
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 2014Peter Martin
 
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 Kubernetesjuniorjbn
 
C#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalC#Web Sec Oct27 2010 Final
C#Web Sec Oct27 2010 FinalRich Helton
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksGerald Krishnan
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Controlbhochhi
 
[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 VikingAndrew Collier
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 
Faq cruise control
Faq cruise controlFaq cruise control
Faq cruise controlnicksrulz
 
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 EleventyLuciano Mammino
 

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

More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Librariesjeresig
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet Sagar Nakul
 
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 Applicationelliando dias
 
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 2Matt Raible
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
Uma introdução ao framework Spring
Uma introdução ao framework SpringUma introdução ao framework Spring
Uma introdução ao framework Springelliando dias
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixBruce Snyder
 

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

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 PicklChristoph 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 classChristoph Pickl
 
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 DolgChristoph Pickl
 
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 PicklChristoph 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 PreiningChristoph Pickl
 
JSUG - TeX Day by Christoph Pickl
JSUG - TeX Day by Christoph PicklJSUG - TeX Day by Christoph Pickl
JSUG - TeX Day by Christoph PicklChristoph 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 PicklChristoph 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 SchuerrerChristoph Pickl
 
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 HubmerChristoph Pickl
 
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 PetrovChristoph Pickl
 
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 SowaChristoph Pickl
 
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 PieberChristoph Pickl
 
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 LangChristoph Pickl
 
JSUG - LaTeX Introduction by Christoph Pickl
JSUG - LaTeX Introduction by Christoph PicklJSUG - LaTeX Introduction by Christoph Pickl
JSUG - LaTeX Introduction by Christoph PicklChristoph Pickl
 
JSUG - OSGi by Michael Greifeneder
JSUG - OSGi by Michael GreifenederJSUG - OSGi by Michael Greifeneder
JSUG - OSGi by Michael GreifenederChristoph Pickl
 
JSUG - Filthy Flex by Christoph Pickl
JSUG - Filthy Flex by Christoph PicklJSUG - Filthy Flex by Christoph Pickl
JSUG - Filthy Flex by Christoph PicklChristoph Pickl
 
JSUG - Seam by Florian Motlik
JSUG - Seam by Florian MotlikJSUG - Seam by Florian Motlik
JSUG - Seam by Florian MotlikChristoph Pickl
 
JSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan ZarnikovJSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan ZarnikovChristoph Pickl
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklChristoph Pickl
 
JSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklJSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklChristoph 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

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

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 configuring 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-config.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 • first 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 JavaConfig Rich Client ... http://www.springframework.org/projects
  • 24. 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