J and I and Me
2010-10-18
  JAOO / Goto Conference 2010: Spring Framework 3.0 On The Way To 3.1 (Jürgen Höller)
In this talk Jürgen showed the current step in the evolution of Spring i.e. the step from version 3.0 to 3.1. As most of the readers will be familiar with 3.0 I will not go into much detail concerning the first part of the talk.

Version 3.0.5 will be the last version for the 3.0 family. The first milestone for Spring 3.1 is scheduled for November - so it won't be long until you get something to play with.

Environment Specific Beans


One important feature will be environment specific beans. Applications usually run on several different environments. There is at least the Java SE environment you use for JUnit tests. You might do staging on a Tomcat server and production on a Java EE server. Beans that manage access to other system might be replaced by mocks for some of them. The goal of the environment specific beans is to deal with these differences in infrastructure while the deployment units are not changed. Usually operations insists that deployment units must not be changed between tests and production.

There are already ways to deal with this challenge. However, if this is supported as a first class part of the configuration it will be much easier and elegant to use. There are still discussions how this feature will be implemented so the details of this feature are not set
in stone.

The Spring Beans will be grouped by environment. The environment itself will be determined by an API that you can extend yourself for maximum flexibility. Placeholders will be resolved depending on the environment.

A possible syntax could be:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
 destroy-method="close">
  <property name="driverClass" value="${database.driver}"/>
  <property name="jdbcUrl" value="${database.url}"/>
  <property name="username" value="${database.username}"/>
  <property name="password" value="${database.password}"/>
</bean>

<beans profile="embedded">
  <jdbc:embedded-database id="dataSource" type="H2">
    <jdbc:script location="/WEB-INF/database/schema-member.sql"/>
    <jdbc:script location="/WEB-INF/database/schema-activity.sql"/>
    <jdbc:script location="/WEB-INF/database/schema-event.sql"/>
    <jdbc:script location="/WEB-INF/database/data.sql"/>
    </jdbc:embedded-database>
</beans>


As you can see the beans element is reused to also cover different environments. As mentioned above the actual implementation might be different - and of course the engineers are happy if you have any feedback!

Improvements for the Java Application Configuration


Java Application Configuration with @Configuration was already introduced in Spring 3.0. In the upcoming release it will be improved to also cover a functionality that resembles the XML namespaces. These namespace are used throughout the framework to configure features like transactions or aop. As the following code sample shows one possible implementation uses a fluent API - in this case to create something that resembles <tx:annotation-driven
/>
.

@Configuration
public void AppConfig {
  @Autowired
  private DataSource dataSource;

  @Bean
  public RewardsService rewardsService() {
    return new RewardsServiceImpl(dataSource);
  }

  @Bean
  public PlatformTransactionManager txManager() {
    return new DataSourceTransactionManager(dataSource);
  }
  
  public TransactionConfiguration txConfig() {
    return annotationDrivenTx().withTransactionManager(txManager());
  }
}

Cache Abstraction


The Spring modules project offered some integration for caching and there is also a very basic cache abstraction. In Spring 3.1 there will be support for EhCache, GemFire, Coherence, etc. Several will be shipped with Spring core but it will also be possible to plug in custom adapters if necessary. The caching itself can then be configured using annotations for example:

@Cacheable
public Owner loadOwner(int id);

@Cacheable(condition="name.length < 10")
public Owner loadOwner(String name);

@CacheInvalidate
public void deleteOwner(int id);

As you can see methods can be marked as cacheable. This can be fine tuned using SpEL (Spring Expression Language). Other methods can be marked as invalidating the cache.

Conversation Management


This feature will allow a user to handle multiple orders in a web application simultaneously - for example in several browser windows or tabs. The state of these must be isolated from one another. The HttpSession is not an option for this because windows share the same
HttpSession.

Spring will manage the window id e.g. by using MVC session form attributes. This is a much simpler problem than the flow support in Spring Web Flow that allows for a simpler solution.

Keeping Up


Spring 3.1 will also support Servlet 3.0 on servers like Tomcat 7 or GlassFish 3. This will include the automatic registration of framework listeners which will make it even easier to use Spring in these settings. Also the support for JSF 2.0 will be improved e.g. for conversations.

Sum Up

Spring 3.1 optimizes Spring in several ways. As the version number indicated polishing and improvements are the main subjects. In particular the cache abstraction is interesting as nowadays a lot of applications need this kind of feature to build scalable solutions.

Labels: , ,

 
Bookmark and Share
Comments: Kommentar veröffentlichen

<< Home
J for Java | I for Internet, iMac, iPod and iPad | Me for me

ARCHIVES
Juni 2005 / Juli 2005 / August 2005 / September 2005 / Oktober 2005 / November 2005 / Dezember 2005 / Januar 2006 / Februar 2006 / März 2006 / April 2006 / Mai 2006 / Juni 2006 / Juli 2006 / August 2006 / September 2006 / Oktober 2006 / November 2006 / Dezember 2006 / Januar 2007 / Februar 2007 / März 2007 / April 2007 / Mai 2007 / Juni 2007 / Juli 2007 / August 2007 / September 2007 / Oktober 2007 / November 2007 / Dezember 2007 / Januar 2008 / April 2008 / Mai 2008 / Juni 2008 / August 2008 / September 2008 / November 2008 / Januar 2009 / Februar 2009 / März 2009 / April 2009 / Mai 2009 / Juni 2009 / Juli 2009 / August 2009 / September 2009 / Oktober 2009 / November 2009 / Dezember 2009 / Januar 2010 / Februar 2010 / März 2010 / April 2010 / Mai 2010 / Juli 2010 / August 2010 / Oktober 2010 / Januar 2011 / Februar 2011 / März 2011 / April 2011 / Mai 2011 / Juni 2011 / August 2011 / September 2011 / November 2011 / Februar 2012 / April 2012 / Mai 2012 / April 2013 / Mai 2013 / Juni 2013 / Januar 2015 / Juli 2015 / Februar 2016 /

Links

Twitter
Google +
Slideshare
Prezi
XING
LinkedIn
Das Spring Buch


Feeds

Feedburner


Impressum
Betreiber und Kontakt:
Eberhard Wolff
Leobschützer Strasse 22
13125 Berlin
E-Mail-Adresse: eberhard.wolff@gmail.com

Verantwortlich für journalistisch-redaktionelle Inhalte:
Eberhard Wolff