SlideShare a Scribd company logo
Spring 3.1

© Zenika 2011       Spring 3.1   1
Speaker's qualifications


     • Arnaud Cogoluègnes
          •     Consultant with Zenika
          •     Has been using Spring since 2005
          •     SpringSource certified trainer
          •     Co-author:
                 • Spring par la pratique, 2nd edition
                 • Spring Dynamic Modules in Action
                 • Spring Batch in Action




© Zenika 2011                                  Spring 3.1   2
Agenda


     •   History
     •   Environment
     •   Java configuration
     •   Spring JPA
     •   Cache abstraction
     •   Spring MVC improvements




© Zenika 2011                      Spring 3.1   3
History


     •   v. 0.9 : june 2003 (foundations)
     •   v. 1.0 : march 2004
     •   v. 1.1 : september 2004
     •   v. 1.2 : may 2005
     •   v. 2.0 : october 2006 (XML namespaces)
     •   v. 2.5 : november 2007 (annotations)
     •   v. 3.0 : décember 2009 (Java config, SpEL, REST)




© Zenika 2011                      Spring 3.1               4
Environment


     • Inside the application context



                            Environment

                Property Source                  Profile
                 Property Source                  Profile




© Zenika 2011                       Spring 3.1              5
Environment / Property Source


     • Do you know this?

   <context:property-placeholder location="database.properties"/>

   <bean id="dataSource"
         class="org.apache.commons.dbcp.BasicDataSource">
     <property name="driverClassName" value="${db.driver}" />
     <property name="url" value="jdbc:${db.url}" />
     <property name="username" value="${db.user}" />
     <property name="password" value="${db.password}" />
   </bean>

                     database.properties
                     db.driver=org.h2.driver
                     db.url=jdbc:h2:mem:db1
                     db.user=sa
                     db.password=

© Zenika 2011                     Spring 3.1                        6
Environment / Property Source


     • Spring 3.1 introduces an abstraction for property sources
     • But what is a PropertySource anyway?


                                   db.driver=org.h2.driver
                                   db.url=jdbc:h2:mem:db1
      Property Source         =    db.user=sa
                                   db.password=




© Zenika 2011                      Spring 3.1                      7
Environment / PropertySource


     • Where do PropertySources come from?
                                              System and environment
                                                     variables
           Properties files                         Properties
                                                  PropertySource
               Resource
            PropertySource

                                  Servlet context and config
                    JNDI               ServletContext/Config
                                          PropertySource
                     Jndi
                PropertySource



© Zenika 2011                    Spring 3.1                            8
Environment / Property Source


     • How to refer to PropertySource?



       <bean id="dataSource"
             class="org.apache.commons.dbcp.BasicDataSource"
             destroy-method="close">
         <property name="driverClass" value="${db.driver}"/>
         <property name="jdbcUrl" value="${db.url}"/>
         <property name="username" value="${db.user}"/>
         <property name="password" value="${db.password}"/>
       </bean>




© Zenika 2011                      Spring 3.1                  9
Environment / Property Source


     • How to refer to PropertySource?

       @Configuration
       public class DatabaseConfiguration {

            @Value("${db.driver}") private String driver;
            @Value("${db.url}") private String url;
            @Value("${db.user}") private String user;
            @Value("${db.password}") private String password;

            @Bean public DataSource dataSource() {
              // creates DataSource
              return dataSource;
            }

       }



© Zenika 2011                         Spring 3.1                10
Environment / PropertySource


     • How to define a PropertySource ?




       <context:property-placeholder
               location="classpath:application.properties" />




© Zenika 2011                      Spring 3.1                   11
Environment / PropertySource


     • How to define a PropertySource ?



       <context:property-placeholder
               properties-ref="applicationProperties" />

       <util:properties id="applicationProperties">
         <prop key="db.driver">org.h2.Driver</prop>
         <prop key="db.url">jdbc:h2:mem:db1</prop>
         <prop key="db.user">sa</prop>
         <prop key="db.password"></prop>
       </util:properties>




© Zenika 2011                      Spring 3.1              12
Environment / PropertySource


     • How to define a PropertySource ?

      <context-param>
             <param-name>contextInitializerClasses</param-name>
             <param-value>com.zenika.SomeInitializer</param-value>
      </context-param>


      public class SomeInitializer
             implements ApplicationContextInitializer
                        <ConfigurableApplicationContext> {

           public void initialize(
                         ConfigurableApplicationContext ctx) {
             PropertySource ps = ...
             ctx.getEnvironment().getPropertySources().addFirst(ps);
           }

      }
© Zenika 2011                        Spring 3.1                        13
Environment / PropertySource


     • Unified way to deal with properties
     • More flexible than simple property placeholder
        • Configurable programmatically, useful for test configs
     • Part of the new Environment abstraction




© Zenika 2011                         Spring 3.1                   14
Environment / Profile




                           Environment

                Property Source                 Profile
                 Property Source                 Profile




© Zenika 2011                      Spring 3.1              15
Environment / Profile



                       Application Context

                    Service                  Repository


         "dev" profile                  "prod" profile

                Datasource                      Datasource




© Zenika 2011                   Spring 3.1                   16
Environment / Profile


     • Different beans for different environments


    <bean class="com.zenika.ContactDao">
      <constructor-arg ref="dataSource" />
    </bean>

    <beans profile="test">
      <jdbc:embedded-database id="dataSource" type="H2" />
    </beans>

    <beans profile="prod">
      <jee:jndi-lookup id="ds"
                       jndi-name="java:comp/env/jdbc/ds" />
    </beans>




© Zenika 2011                      Spring 3.1                 17
Environment / Profile


     • Let's reach the clouds!


  <bean class="com.zenika.ContactDao">
    <constructor-arg ref="dataSource" />
  </bean>

  <beans profile="dev">
    <jdbc:embedded-database id="dataSource" type="H2" />
  </beans>

  <beans profile="cloud">
    <cloud:data-source id="dataSource" service-name="contactDs"/>
  </beans>




© Zenika 2011                    Spring 3.1                         18
Environment / Profile


     • Creating the application context for the test profile



    GenericXmlApplicationContext ctx =
      new GenericXmlApplicationContext();
    ctx.getEnvironment().setActiveProfiles("test");
    ctx.load("classpath:/application-context.xml");
    ctx.refresh();




© Zenika 2011                        Spring 3.1                19
Environment / Profile


     • Activating a profile declaratively




    -Dspring.profiles.active="prod"




© Zenika 2011                        Spring 3.1   20
Environment / Profile


     • Bootstrapping with the TestContext framework

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:/application-context.xml")
    @ActiveProfiles("test")
    public class ProfileTest {

        @Autowired private ContactDao contactDao;


        @Test public void getContact() throws Exception {
          ...
        }

    }




© Zenika 2011                      Spring 3.1                     21
Environment / Profile


     • Just « prod » profile



    <bean class="com.zenika.spring31.ContactDao">
      <constructor-arg ref="dataSource" />
    </bean>

    <beans profile="prod">
      <jee:jndi-lookup id="ds"
                       jndi-name="java:comp/env/jdbc/ds" />
    </beans>




© Zenika 2011                    Spring 3.1                   22
Environment / Profile


     • Override what you need in the test
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(
      loader=AnnotationConfigContextLoader.class
    )
    public class SpecialProfileTest {

        @Autowired private ContactDao contactDao;

        @Test public void getContact() throws Exception {
          ...
        }

        @Configuration
        @ImportResource("classpath:/application-context.xml")
        static class ContextConfiguration {
          @Bean public DataSource dataSource() {
            return new EmbeddedDatabaseBuilder().build();
          }
        }
    }

© Zenika 2011                          Spring 3.1               23
Java configuration


     • Nothing equivalent to XML namespaces so far...



    @Transactional
    @Repository
    public class HibernateContactRepo { ... }

    <context:component-scan base-package="com.zenika" />

    <tx:annotation-driven />




© Zenika 2011                    Spring 3.1                24
Java configuration


     • Annotations equivalent to common XML shortcuts



    @Transactional
    @Repository
    public class HibernateContactRepo { ... }

    @Configuration
    @EnableTransactionManagement
    @ComponentScan(basePackageClasses=HibernateContactRepo.class)
    public class ContextConfiguration { ... }




© Zenika 2011                    Spring 3.1                         25
Java configuration


     • Annotations equivalent to common XML shortcuts
    @Configuration
    @EnableTransactionManagement
    @ComponentScan(basePackageClasses=HibernateContactRepo.class)
    public class ContextConfiguration {

        @Bean public SessionFactory sf() throws Exception {
          return new AnnotationSessionFactoryBuilder()
            .setDataSource(dataSource())
            .setPackagesToScan(Contact.class.getPackage().getName())
            .buildSessionFactory();
        }

        @Bean public PlatformTransactionManager tm() throws Exception {
          return new HibernateTransactionManager(sf());
        }

        @Bean public DataSource dataSource() {
          return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2).build();
        }

    }
© Zenika 2011                          Spring 3.1                         26
Spring JPA


     • More support for persistence in Spring JPA

    public interface ContactRepository
           extends JpaRepository<Contact, Long> { }

    <jpa:repositories base-package="com.zenika.jpa" />


    long initialCount = contactRepo.count();
    Contact contact = new Contact();
    contact.setFirstname("Arnaud");
    contact.setLastname("Cogoluègnes");
    contactRepo.save(contact);
    Assert.assertEquals(initialCount+1, contactRepo.count());




© Zenika 2011                     Spring 3.1                    27
Spring JPA


     • Define your own method, following conventions



    public interface ContactRepository
                     extends JpaRepository<Contact, Long> {

        List<Contact> findByFirstname(String firstname);

    }
  List<Contact> contacts = contactRepo.findByFirstname("Arnaud");




© Zenika 2011                      Spring 3.1                   28
Spring JPA


      • Define JPQL queries for methods


  public interface ContactRepository
                   extends JpaRepository<Contact, Long> {

      @Query("from Contact c where lower(c.firstname) = lower(?1)")
      List<Contact> find(String search);

  }
   List<Contact> contacts = contactRepo.find("arnaud");




© Zenika 2011                     Spring 3.1                          29
Spring JPA


     • Built-in support for pagination



   Pageable request = new PageRequest(1,2,new Sort("lastname"));
   Page<Contact> page = contactRepo.findAll(request);

   List<Contact> contacts = page.getContent();
   long total = page.getTotalElements();
   long number = page.getNumberOfElements();




© Zenika 2011                       Spring 3.1                     30
Quick note on Spring Data


     • Spring JPA is part of the Spring Data project
     • Spring Data is an umbrella project
     • Spring Data provides Spring support for « new » data
       access technologies
        • MongoDB, Neo4j, Riak, Redis, Hadoop
     • Support planned for additional NoSQL technologies
        • HBase, Cassandra, CouchDB
     • Don't hesitate to check out Spring Data!
        • http://www.springsource.org/spring-data




© Zenika 2011                     Spring 3.1                  31
Cache support in Spring 3.1


     • What about some transparent cache on method calls?

   public interface ContactRepository
                    extends JpaRepository<Contact, Long> {

       Contact findOne(Long id);

   }

   Contact contact = contactRepo.findOne(contact.getId());
   contact = contactRepo.findOne(contact.getId());

   Hibernate: select contact0_.id as id0_0_, ...
   Hibernate: select contact0_.id as id0_0_, ...




© Zenika 2011                      Spring 3.1                32
Cache support in Spring 3.1


     • Let's combine Spring JPA and Spring 3.1's cache support !
          • NB: the cache support works on any kinds of beans
   public interface ContactRepository
                    extends JpaRepository<Contact, Long> {

       @Cacheable("contacts")
       Contact findOne(Long id);

   }

   Contact contact = contactRepo.findOne(contact.getId());
   contact         = contactRepo.findOne(contact.getId());

   Hibernate: select contact0_.id as id0_0_, ...



© Zenika 2011                         Spring 3.1                   33
Cache support in Spring 3.1


     • This is how to configure the cache


   <cache:annotation-driven />

   <bean id="cacheManager"
         class="o.s.cache.support.SimpleCacheManager">
     <property name="caches">
       <set>
         <bean class="o.s.cache.concurrent.ConcurrentMapCache"
               c:name="contacts" />
       </set>
     </property>
   </bean>




© Zenika 2011                      Spring 3.1                    34
Cache support in Spring 3.1


     • The cache support is an abstraction
     • The Spring Framework provides implementations
          • SimpleCacheManager
             • Uses collections of caches
             • Useful for testing or small, non-distributed environments
          • EhCacheCacheManager
             • Backed up by Ehcache
     • The Spring Gemfire project ships with an implementation




© Zenika 2011                              Spring 3.1                      35
Cache support in Spring 3.1


     • Can use expression for keys
   public interface ContactRepository
                    extends JpaRepository<Contact, Long> {

       @Cacheable(value="contacts",key="#p0+'.'+#p1")
       Contact findByLastnameAndFirstname(String lastname,
                                          String firstname);

   }
   Contact contact = contactRepo.findByLastnameAndFirstname(
     "Cogoluègnes", "Arnaud");
   contact         = contactRepo.findByLastnameAndFirstname(
     "Cogoluègnes", "Arnaud");

   Hibernate: select contact0_.id as id0_, ...



© Zenika 2011                      Spring 3.1                  36
Cache support in Spring 3.1


     • Method can do some housekeeping with @CacheEvict


   @Transactional
   public interface ContactRepository
                    extends JpaRepository<Contact, Long> {

       @Cacheable("contacts")
       Contact findOne(Long id);

       @CacheEvict(value="contacts",key="#p0.id")
       Contact save(Contact contact);

   }




© Zenika 2011                      Spring 3.1                37
Cache support in Spring 3.1


     • Spring's cache support can be used
          • on the data access layer
             • replaces 2nd level cache or provides cache for a JDBC-based
                layer
          • at the web tier level
             • caches business services calls or web services calls




© Zenika 2011                            Spring 3.1                          38
Spring MVC enhancements


     • Easier registration of HttpMessageConverters
     • But what is a HttpMessageConverter anyway?
     • HttpMessageConverters are used in Spring's REST
       support
          • Java object to HTTP response conversion
             • From Java to XML, JSON, etc.
          • HTTP request to Java object conversion
             • From XML, JSON to Java
     • On the server but on the client side as well...




© Zenika 2011                         Spring 3.1         39
Spring MVC enhancements


     • Easier registration with a dedicated XML tag
          • Used to be directly at the HandlerAdapter level



  <mvc:annotation-driven>
    <mvc:message-converters register-defaults="false">
      <bean class="com.zenika.web.ContactHttpMessageConverter" />
    </mvc:message-converters>
  </mvc:annotation-driven>




© Zenika 2011                         Spring 3.1                    40
Spring MVC enhancements


      • Java-based configuration
          • Same as <mvc:annotation-driven />

  @Configuration
  @EnableWebMvc
  public class WebConfig extends WebMvcConfigurerAdapter {

       @Override
       public void configureMessageConverters(
                     List<HttpMessageConverter<?>> converters) {
         converters.add(new ContactHttpMessageConverter());
       }

  }




© Zenika 2011                         Spring 3.1                   41
Spring MVC enhancements


      • Big refactoring on the way to process annotations


  @Controller
  public class ContactController {

       @Autowired private ContactRepository repo;

       @RequestMapping(value="/contacts/{id}",
                       method=RequestMethod.GET
       )
       @ResponseBody
       public Contact get(@PathVariable Long id) {
         return repo.findOne(id);
       }

  }


© Zenika 2011                      Spring 3.1               42
Spring MVC enhancements


     • Who used to process annotations like @RequestMapping,
       @RequestParam, etc?
     • Answer: the AnnotationMethodHandlerAdapter.
     • Processing was hard-coded in the class
     • Spring 3.1 introduced the HandlerMethod abstraction
          • RequestMappingHandlerMapping
          • RequestMappingHandlerAdapter




© Zenika 2011                   Spring 3.1                     43
Spring MVC enhancements


     • Consequences of the HandlerMethod abstraction
          • Backward compatible (@RequestMapping, @RequestParam
            & co).
          • More fine-grained control over controller method execution
          • Possible interception around the invocation of the controller
          • Pluggable mechanism on method argument
                • You can create your own @RequestParam-like annotations!
                • Check the HandlerMethodArgumentResolver and
                  HandlerMethodReturnValueHandler interfaces




© Zenika 2011                              Spring 3.1                       44
Support for Servlet 3.0


     • Servlet 3.0 allows for programmatic registration
        • ServletContext.addServlet(String, Servlet)
        • ServletContext.addFilter(String, Filter)
     • Hook for frameworks
        • ServletContainerInitializer
        • Implementations listed in META-INF/services
     • In Spring: SpringServletContainerInitializer




© Zenika 2011                      Spring 3.1             45
Support for Servlet 3.0


     • SpringServletContainerInitializer triggers
       WebApplicationInitializers
     • WebApplicationInitializer
          • The API to use
          • Detected and called by Spring (through the web container)
          • Used for initialization
                • Registering a DispatcherServlet
                • Bootstrapping the Spring ApplicationContext




© Zenika 2011                            Spring 3.1                     46
Support for Servlet 3.0


      • No need of web.xml anymore
  public class ZenContactInitializer
         implements WebApplicationInitializer {

      @Override
      public void onStartup(ServletContext sc) throws ServletException {
        AnnotationConfigWebApplicationContext rootContext =
          new AnnotationConfigWebApplicationContext();
        rootContext.register(WebConfig.class);
        sc.addListener(new ContextLoaderListener(rootContext));

          AnnotationConfigWebApplicationContext dispatcherContext =
            new AnnotationConfigWebApplicationContext();
          dispatcherContext.register(DispatcherConfig.class);

          ServletRegistration.Dynamic dispatcher = sc.addServlet(
            "dispatcher", new DispatcherServlet(dispatcherContext));
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/main");
      }
  }

© Zenika 2011                           Spring 3.1                         47
Resources

     • Summary
          • http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/
          • http://blog.springsource.com/2011/06/09/spring-framework-3-1-m2-released/
     • Environment
          • http://blog.springsource.com/2011/02/14/spring-3-1-m1-introducing-profile/
          • http://blog.springsource.com/2011/06/21/spring-3-1-m2-testing-with-configuration-
            classes-and-profiles/
          • http://blog.springsource.com/2011/02/15/spring-3-1-m1-unified-property-management/
     • Cache abstraction
          • http://blog.springsource.com/2011/02/23/spring-3-1-m1-caching/
     • Spring JPA
          • http://blog.springsource.com/2011/02/10/getting-started-with-spring-data-jpa/
          • http://blog.springsource.com/2011/07/27/fine-tuning-spring-data-repositories/
     • Spring MVC
          • http://blog.springsource.com/2011/02/21/spring-3-1-m1-mvc-namespace-
            enhancements-and-configuration/
          • http://blog.springsource.com/2011/06/13/spring-3-1-m2-spring-mvc-enhancements-2/
© Zenika 2011                                      Spring 3.1                                    48
Questions ?




© Zenika 2011        Spring 3.1   49

More Related Content

What's hot

5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
Arun Gupta
 
Hadoop 101
Hadoop 101Hadoop 101
Hadoop 101
Nader Ganayem
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3
IMC Institute
 
Sel study notes
Sel study notesSel study notes
Sel study notes
Lalit Singh
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
Smita B Kumar
 
Understanding
Understanding Understanding
Understanding
Arun Gupta
 
Connection Pooling
Connection PoolingConnection Pooling
Connection Pooling
Wings Interactive
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Thorben Janssen
 
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Hitesh-Java
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
sourabh aggarwal
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
Anatole Tresch
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
Joshua Long
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Atul Saurabh
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
James Johnson
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
Akankshaji
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
Fahad Golra
 
Weblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationWeblogic Administration Managed Server migration
Weblogic Administration Managed Server migration
Rakesh Gujjarlapudi
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 

What's hot (19)

5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
 
Hadoop 101
Hadoop 101Hadoop 101
Hadoop 101
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3
 
Sel study notes
Sel study notesSel study notes
Sel study notes
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
Understanding
Understanding Understanding
Understanding
 
Connection Pooling
Connection PoolingConnection Pooling
Connection Pooling
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
 
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 
Weblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationWeblogic Administration Managed Server migration
Weblogic Administration Managed Server migration
 
Spring Core
Spring CoreSpring Core
Spring Core
 

Viewers also liked

Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projetsChti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
Ch'ti JUG
 
Adobe flash platform java
Adobe flash platform javaAdobe flash platform java
Adobe flash platform java
Ch'ti JUG
 
Bonita Open Solution
Bonita Open SolutionBonita Open Solution
Bonita Open Solution
Ch'ti JUG
 
MC3SI Chti Jug Soiree Agilite
MC3SI Chti Jug Soiree AgiliteMC3SI Chti Jug Soiree Agilite
MC3SI Chti Jug Soiree Agilite
Ch'ti JUG
 
Agile Day Tunisia 2012 - Agile entre opportunités et résistance
Agile Day Tunisia 2012 - Agile entre opportunités et résistanceAgile Day Tunisia 2012 - Agile entre opportunités et résistance
Agile Day Tunisia 2012 - Agile entre opportunités et résistance
Tunisia Scrum User Group
 
Java 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaJava 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambda
Ch'ti JUG
 
Retrospectives agiles - fiches pratiques
Retrospectives agiles - fiches pratiquesRetrospectives agiles - fiches pratiques
Retrospectives agiles - fiches pratiques
Sylvain Loubradou
 
Jolocom contribution to the AGILE-IoT project
Jolocom contribution to the AGILE-IoT projectJolocom contribution to the AGILE-IoT project
Jolocom contribution to the AGILE-IoT project
AGILE IoT
 
Fundamentals of Agile Methodologies - Part I
Fundamentals of Agile Methodologies - Part IFundamentals of Agile Methodologies - Part I
Fundamentals of Agile Methodologies - Part I
Gopinath Ramakrishnan, Ph.D, CSM
 

Viewers also liked (9)

Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projetsChti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
 
Adobe flash platform java
Adobe flash platform javaAdobe flash platform java
Adobe flash platform java
 
Bonita Open Solution
Bonita Open SolutionBonita Open Solution
Bonita Open Solution
 
MC3SI Chti Jug Soiree Agilite
MC3SI Chti Jug Soiree AgiliteMC3SI Chti Jug Soiree Agilite
MC3SI Chti Jug Soiree Agilite
 
Agile Day Tunisia 2012 - Agile entre opportunités et résistance
Agile Day Tunisia 2012 - Agile entre opportunités et résistanceAgile Day Tunisia 2012 - Agile entre opportunités et résistance
Agile Day Tunisia 2012 - Agile entre opportunités et résistance
 
Java 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaJava 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambda
 
Retrospectives agiles - fiches pratiques
Retrospectives agiles - fiches pratiquesRetrospectives agiles - fiches pratiques
Retrospectives agiles - fiches pratiques
 
Jolocom contribution to the AGILE-IoT project
Jolocom contribution to the AGILE-IoT projectJolocom contribution to the AGILE-IoT project
Jolocom contribution to the AGILE-IoT project
 
Fundamentals of Agile Methodologies - Part I
Fundamentals of Agile Methodologies - Part IFundamentals of Agile Methodologies - Part I
Fundamentals of Agile Methodologies - Part I
 

Similar to Spring 3.1

Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
Joshua Long
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
Arun Gupta
 
Spring database - part2
Spring database -  part2Spring database -  part2
Spring database - part2
Santosh Kumar Kar
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
Arun Gupta
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
JAX London
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011
Sam Brannen
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
Yiwei Ma
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
IMC Institute
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
Anand kalla
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster1
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster1
 
04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop
Chuong Nguyen
 
Spring 3.1 Features Worth Knowing About
Spring 3.1 Features Worth Knowing AboutSpring 3.1 Features Worth Knowing About
Spring 3.1 Features Worth Knowing About
Rossen Stoyanchev
 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Sam Brannen
 
SpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.pptSpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.ppt
imjdabhinawpandey
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
AnilKumar Etagowni
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
Arun Gupta
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Arun Gupta
 
Maven
MavenMaven
Maven
javeed_mhd
 

Similar to Spring 3.1 (20)

Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
Spring database - part2
Spring database -  part2Spring database -  part2
Spring database - part2
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
 
04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop
 
Spring 3.1 Features Worth Knowing About
Spring 3.1 Features Worth Knowing AboutSpring 3.1 Features Worth Knowing About
Spring 3.1 Features Worth Knowing About
 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
 
SpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.pptSpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.ppt
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
 
Maven
MavenMaven
Maven
 

Recently uploaded

Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
shanihomely
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
Tatiana Al-Chueyr
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
aakash malhotra
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
Priyanka Aash
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
HackersList
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
SynapseIndia
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
shyamraj55
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Muhammad Ali
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
Zilliz
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
Priyanka Aash
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
Axel Rennoch
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
Figma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdfFigma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdf
Management Institute of Skills Development
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Zilliz
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
CEPTES Software Inc
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
RaminGhanbari2
 

Recently uploaded (20)

Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
 
Figma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdfFigma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdf
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
 

Spring 3.1

  • 1. Spring 3.1 © Zenika 2011 Spring 3.1 1
  • 2. Speaker's qualifications • Arnaud Cogoluègnes • Consultant with Zenika • Has been using Spring since 2005 • SpringSource certified trainer • Co-author: • Spring par la pratique, 2nd edition • Spring Dynamic Modules in Action • Spring Batch in Action © Zenika 2011 Spring 3.1 2
  • 3. Agenda • History • Environment • Java configuration • Spring JPA • Cache abstraction • Spring MVC improvements © Zenika 2011 Spring 3.1 3
  • 4. History • v. 0.9 : june 2003 (foundations) • v. 1.0 : march 2004 • v. 1.1 : september 2004 • v. 1.2 : may 2005 • v. 2.0 : october 2006 (XML namespaces) • v. 2.5 : november 2007 (annotations) • v. 3.0 : décember 2009 (Java config, SpEL, REST) © Zenika 2011 Spring 3.1 4
  • 5. Environment • Inside the application context Environment Property Source Profile Property Source Profile © Zenika 2011 Spring 3.1 5
  • 6. Environment / Property Source • Do you know this? <context:property-placeholder location="database.properties"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${db.driver}" /> <property name="url" value="jdbc:${db.url}" /> <property name="username" value="${db.user}" /> <property name="password" value="${db.password}" /> </bean> database.properties db.driver=org.h2.driver db.url=jdbc:h2:mem:db1 db.user=sa db.password= © Zenika 2011 Spring 3.1 6
  • 7. Environment / Property Source • Spring 3.1 introduces an abstraction for property sources • But what is a PropertySource anyway? db.driver=org.h2.driver db.url=jdbc:h2:mem:db1 Property Source = db.user=sa db.password= © Zenika 2011 Spring 3.1 7
  • 8. Environment / PropertySource • Where do PropertySources come from? System and environment variables Properties files Properties PropertySource Resource PropertySource Servlet context and config JNDI ServletContext/Config PropertySource Jndi PropertySource © Zenika 2011 Spring 3.1 8
  • 9. Environment / Property Source • How to refer to PropertySource? <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClass" value="${db.driver}"/> <property name="jdbcUrl" value="${db.url}"/> <property name="username" value="${db.user}"/> <property name="password" value="${db.password}"/> </bean> © Zenika 2011 Spring 3.1 9
  • 10. Environment / Property Source • How to refer to PropertySource? @Configuration public class DatabaseConfiguration { @Value("${db.driver}") private String driver; @Value("${db.url}") private String url; @Value("${db.user}") private String user; @Value("${db.password}") private String password; @Bean public DataSource dataSource() { // creates DataSource return dataSource; } } © Zenika 2011 Spring 3.1 10
  • 11. Environment / PropertySource • How to define a PropertySource ? <context:property-placeholder location="classpath:application.properties" /> © Zenika 2011 Spring 3.1 11
  • 12. Environment / PropertySource • How to define a PropertySource ? <context:property-placeholder properties-ref="applicationProperties" /> <util:properties id="applicationProperties"> <prop key="db.driver">org.h2.Driver</prop> <prop key="db.url">jdbc:h2:mem:db1</prop> <prop key="db.user">sa</prop> <prop key="db.password"></prop> </util:properties> © Zenika 2011 Spring 3.1 12
  • 13. Environment / PropertySource • How to define a PropertySource ? <context-param> <param-name>contextInitializerClasses</param-name> <param-value>com.zenika.SomeInitializer</param-value> </context-param> public class SomeInitializer implements ApplicationContextInitializer <ConfigurableApplicationContext> { public void initialize( ConfigurableApplicationContext ctx) { PropertySource ps = ... ctx.getEnvironment().getPropertySources().addFirst(ps); } } © Zenika 2011 Spring 3.1 13
  • 14. Environment / PropertySource • Unified way to deal with properties • More flexible than simple property placeholder • Configurable programmatically, useful for test configs • Part of the new Environment abstraction © Zenika 2011 Spring 3.1 14
  • 15. Environment / Profile Environment Property Source Profile Property Source Profile © Zenika 2011 Spring 3.1 15
  • 16. Environment / Profile Application Context Service Repository "dev" profile "prod" profile Datasource Datasource © Zenika 2011 Spring 3.1 16
  • 17. Environment / Profile • Different beans for different environments <bean class="com.zenika.ContactDao"> <constructor-arg ref="dataSource" /> </bean> <beans profile="test"> <jdbc:embedded-database id="dataSource" type="H2" /> </beans> <beans profile="prod"> <jee:jndi-lookup id="ds" jndi-name="java:comp/env/jdbc/ds" /> </beans> © Zenika 2011 Spring 3.1 17
  • 18. Environment / Profile • Let's reach the clouds! <bean class="com.zenika.ContactDao"> <constructor-arg ref="dataSource" /> </bean> <beans profile="dev"> <jdbc:embedded-database id="dataSource" type="H2" /> </beans> <beans profile="cloud"> <cloud:data-source id="dataSource" service-name="contactDs"/> </beans> © Zenika 2011 Spring 3.1 18
  • 19. Environment / Profile • Creating the application context for the test profile GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.getEnvironment().setActiveProfiles("test"); ctx.load("classpath:/application-context.xml"); ctx.refresh(); © Zenika 2011 Spring 3.1 19
  • 20. Environment / Profile • Activating a profile declaratively -Dspring.profiles.active="prod" © Zenika 2011 Spring 3.1 20
  • 21. Environment / Profile • Bootstrapping with the TestContext framework @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/application-context.xml") @ActiveProfiles("test") public class ProfileTest { @Autowired private ContactDao contactDao; @Test public void getContact() throws Exception { ... } } © Zenika 2011 Spring 3.1 21
  • 22. Environment / Profile • Just « prod » profile <bean class="com.zenika.spring31.ContactDao"> <constructor-arg ref="dataSource" /> </bean> <beans profile="prod"> <jee:jndi-lookup id="ds" jndi-name="java:comp/env/jdbc/ds" /> </beans> © Zenika 2011 Spring 3.1 22
  • 23. Environment / Profile • Override what you need in the test @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( loader=AnnotationConfigContextLoader.class ) public class SpecialProfileTest { @Autowired private ContactDao contactDao; @Test public void getContact() throws Exception { ... } @Configuration @ImportResource("classpath:/application-context.xml") static class ContextConfiguration { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder().build(); } } } © Zenika 2011 Spring 3.1 23
  • 24. Java configuration • Nothing equivalent to XML namespaces so far... @Transactional @Repository public class HibernateContactRepo { ... } <context:component-scan base-package="com.zenika" /> <tx:annotation-driven /> © Zenika 2011 Spring 3.1 24
  • 25. Java configuration • Annotations equivalent to common XML shortcuts @Transactional @Repository public class HibernateContactRepo { ... } @Configuration @EnableTransactionManagement @ComponentScan(basePackageClasses=HibernateContactRepo.class) public class ContextConfiguration { ... } © Zenika 2011 Spring 3.1 25
  • 26. Java configuration • Annotations equivalent to common XML shortcuts @Configuration @EnableTransactionManagement @ComponentScan(basePackageClasses=HibernateContactRepo.class) public class ContextConfiguration { @Bean public SessionFactory sf() throws Exception { return new AnnotationSessionFactoryBuilder() .setDataSource(dataSource()) .setPackagesToScan(Contact.class.getPackage().getName()) .buildSessionFactory(); } @Bean public PlatformTransactionManager tm() throws Exception { return new HibernateTransactionManager(sf()); } @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseType.H2).build(); } } © Zenika 2011 Spring 3.1 26
  • 27. Spring JPA • More support for persistence in Spring JPA public interface ContactRepository extends JpaRepository<Contact, Long> { } <jpa:repositories base-package="com.zenika.jpa" /> long initialCount = contactRepo.count(); Contact contact = new Contact(); contact.setFirstname("Arnaud"); contact.setLastname("Cogoluègnes"); contactRepo.save(contact); Assert.assertEquals(initialCount+1, contactRepo.count()); © Zenika 2011 Spring 3.1 27
  • 28. Spring JPA • Define your own method, following conventions public interface ContactRepository extends JpaRepository<Contact, Long> { List<Contact> findByFirstname(String firstname); } List<Contact> contacts = contactRepo.findByFirstname("Arnaud"); © Zenika 2011 Spring 3.1 28
  • 29. Spring JPA • Define JPQL queries for methods public interface ContactRepository extends JpaRepository<Contact, Long> { @Query("from Contact c where lower(c.firstname) = lower(?1)") List<Contact> find(String search); } List<Contact> contacts = contactRepo.find("arnaud"); © Zenika 2011 Spring 3.1 29
  • 30. Spring JPA • Built-in support for pagination Pageable request = new PageRequest(1,2,new Sort("lastname")); Page<Contact> page = contactRepo.findAll(request); List<Contact> contacts = page.getContent(); long total = page.getTotalElements(); long number = page.getNumberOfElements(); © Zenika 2011 Spring 3.1 30
  • 31. Quick note on Spring Data • Spring JPA is part of the Spring Data project • Spring Data is an umbrella project • Spring Data provides Spring support for « new » data access technologies • MongoDB, Neo4j, Riak, Redis, Hadoop • Support planned for additional NoSQL technologies • HBase, Cassandra, CouchDB • Don't hesitate to check out Spring Data! • http://www.springsource.org/spring-data © Zenika 2011 Spring 3.1 31
  • 32. Cache support in Spring 3.1 • What about some transparent cache on method calls? public interface ContactRepository extends JpaRepository<Contact, Long> { Contact findOne(Long id); } Contact contact = contactRepo.findOne(contact.getId()); contact = contactRepo.findOne(contact.getId()); Hibernate: select contact0_.id as id0_0_, ... Hibernate: select contact0_.id as id0_0_, ... © Zenika 2011 Spring 3.1 32
  • 33. Cache support in Spring 3.1 • Let's combine Spring JPA and Spring 3.1's cache support ! • NB: the cache support works on any kinds of beans public interface ContactRepository extends JpaRepository<Contact, Long> { @Cacheable("contacts") Contact findOne(Long id); } Contact contact = contactRepo.findOne(contact.getId()); contact = contactRepo.findOne(contact.getId()); Hibernate: select contact0_.id as id0_0_, ... © Zenika 2011 Spring 3.1 33
  • 34. Cache support in Spring 3.1 • This is how to configure the cache <cache:annotation-driven /> <bean id="cacheManager" class="o.s.cache.support.SimpleCacheManager"> <property name="caches"> <set> <bean class="o.s.cache.concurrent.ConcurrentMapCache" c:name="contacts" /> </set> </property> </bean> © Zenika 2011 Spring 3.1 34
  • 35. Cache support in Spring 3.1 • The cache support is an abstraction • The Spring Framework provides implementations • SimpleCacheManager • Uses collections of caches • Useful for testing or small, non-distributed environments • EhCacheCacheManager • Backed up by Ehcache • The Spring Gemfire project ships with an implementation © Zenika 2011 Spring 3.1 35
  • 36. Cache support in Spring 3.1 • Can use expression for keys public interface ContactRepository extends JpaRepository<Contact, Long> { @Cacheable(value="contacts",key="#p0+'.'+#p1") Contact findByLastnameAndFirstname(String lastname, String firstname); } Contact contact = contactRepo.findByLastnameAndFirstname( "Cogoluègnes", "Arnaud"); contact = contactRepo.findByLastnameAndFirstname( "Cogoluègnes", "Arnaud"); Hibernate: select contact0_.id as id0_, ... © Zenika 2011 Spring 3.1 36
  • 37. Cache support in Spring 3.1 • Method can do some housekeeping with @CacheEvict @Transactional public interface ContactRepository extends JpaRepository<Contact, Long> { @Cacheable("contacts") Contact findOne(Long id); @CacheEvict(value="contacts",key="#p0.id") Contact save(Contact contact); } © Zenika 2011 Spring 3.1 37
  • 38. Cache support in Spring 3.1 • Spring's cache support can be used • on the data access layer • replaces 2nd level cache or provides cache for a JDBC-based layer • at the web tier level • caches business services calls or web services calls © Zenika 2011 Spring 3.1 38
  • 39. Spring MVC enhancements • Easier registration of HttpMessageConverters • But what is a HttpMessageConverter anyway? • HttpMessageConverters are used in Spring's REST support • Java object to HTTP response conversion • From Java to XML, JSON, etc. • HTTP request to Java object conversion • From XML, JSON to Java • On the server but on the client side as well... © Zenika 2011 Spring 3.1 39
  • 40. Spring MVC enhancements • Easier registration with a dedicated XML tag • Used to be directly at the HandlerAdapter level <mvc:annotation-driven> <mvc:message-converters register-defaults="false"> <bean class="com.zenika.web.ContactHttpMessageConverter" /> </mvc:message-converters> </mvc:annotation-driven> © Zenika 2011 Spring 3.1 40
  • 41. Spring MVC enhancements • Java-based configuration • Same as <mvc:annotation-driven /> @Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Override public void configureMessageConverters( List<HttpMessageConverter<?>> converters) { converters.add(new ContactHttpMessageConverter()); } } © Zenika 2011 Spring 3.1 41
  • 42. Spring MVC enhancements • Big refactoring on the way to process annotations @Controller public class ContactController { @Autowired private ContactRepository repo; @RequestMapping(value="/contacts/{id}", method=RequestMethod.GET ) @ResponseBody public Contact get(@PathVariable Long id) { return repo.findOne(id); } } © Zenika 2011 Spring 3.1 42
  • 43. Spring MVC enhancements • Who used to process annotations like @RequestMapping, @RequestParam, etc? • Answer: the AnnotationMethodHandlerAdapter. • Processing was hard-coded in the class • Spring 3.1 introduced the HandlerMethod abstraction • RequestMappingHandlerMapping • RequestMappingHandlerAdapter © Zenika 2011 Spring 3.1 43
  • 44. Spring MVC enhancements • Consequences of the HandlerMethod abstraction • Backward compatible (@RequestMapping, @RequestParam & co). • More fine-grained control over controller method execution • Possible interception around the invocation of the controller • Pluggable mechanism on method argument • You can create your own @RequestParam-like annotations! • Check the HandlerMethodArgumentResolver and HandlerMethodReturnValueHandler interfaces © Zenika 2011 Spring 3.1 44
  • 45. Support for Servlet 3.0 • Servlet 3.0 allows for programmatic registration • ServletContext.addServlet(String, Servlet) • ServletContext.addFilter(String, Filter) • Hook for frameworks • ServletContainerInitializer • Implementations listed in META-INF/services • In Spring: SpringServletContainerInitializer © Zenika 2011 Spring 3.1 45
  • 46. Support for Servlet 3.0 • SpringServletContainerInitializer triggers WebApplicationInitializers • WebApplicationInitializer • The API to use • Detected and called by Spring (through the web container) • Used for initialization • Registering a DispatcherServlet • Bootstrapping the Spring ApplicationContext © Zenika 2011 Spring 3.1 46
  • 47. Support for Servlet 3.0 • No need of web.xml anymore public class ZenContactInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext sc) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebConfig.class); sc.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(DispatcherConfig.class); ServletRegistration.Dynamic dispatcher = sc.addServlet( "dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/main"); } } © Zenika 2011 Spring 3.1 47
  • 48. Resources • Summary • http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/ • http://blog.springsource.com/2011/06/09/spring-framework-3-1-m2-released/ • Environment • http://blog.springsource.com/2011/02/14/spring-3-1-m1-introducing-profile/ • http://blog.springsource.com/2011/06/21/spring-3-1-m2-testing-with-configuration- classes-and-profiles/ • http://blog.springsource.com/2011/02/15/spring-3-1-m1-unified-property-management/ • Cache abstraction • http://blog.springsource.com/2011/02/23/spring-3-1-m1-caching/ • Spring JPA • http://blog.springsource.com/2011/02/10/getting-started-with-spring-data-jpa/ • http://blog.springsource.com/2011/07/27/fine-tuning-spring-data-repositories/ • Spring MVC • http://blog.springsource.com/2011/02/21/spring-3-1-m1-mvc-namespace- enhancements-and-configuration/ • http://blog.springsource.com/2011/06/13/spring-3-1-m2-spring-mvc-enhancements-2/ © Zenika 2011 Spring 3.1 48
  • 49. Questions ? © Zenika 2011 Spring 3.1 49