J and I and Me
2010-07-07
  Limiting the Visibility of Spring Beans
Lately I have been working on concepts for the configuration of large Spring applications. The basic concept to build large system is well established in computer science: Break the system down in smaller blocks and build each of the blocks. Have the blocks talk to each other only in defined ways to decouple. This means that the blocks can easily be changed internally as long as the external properties stay the same. Transferred to Spring this means that the Spring configuration of the system must be broken down into parts. This is very well possible and actually already a best practice.

However, there is one problem: The Spring configuration has only a global visibility. I.e. every Spring bean can be used anywhere in the configuration. There are some ways to tackle this problem - that is beyond the scope of this posting.

There used to be a very elegant solution to this in the Spring Java Configuration introduced in Spring 3.0:

@Configuration
public class JavaConfiguration {

 @Bean(destroyMethod = "close")
 protected DataSource dataSource() {...}

 @Bean
 public EntityManagerFactory entityManagerFactory() {...}

 @Bean
 protected JpaVendorAdapter jpaVendorAdapter() {...}
}


This configuration creates Spring beans called dataSource, entityManagerFactory and jpaVendoreAdapter by calling the respective methods. Now the trick is: If you use the protected keyword the beans are not visible outside this class i.e. in particular they are not visible in an XML configuration that uses this class or in other Spring configuration classes. At least that is how it used to be - this feature is gone now. If you agree with me that this is an important feature - please vote for http://jira.springframework.org/browse/SPR-7170 to bring it back!

Labels: ,

  15:30 6 comments
Bookmark and Share
  Changing Languages
For the future I plan to continue this blog in English. German limits the audience significantly. Also I am not concerned about only the German market - I am working on consulting and trainings products for the global market. I believe most Germans know enough English to still follow the blog. Let me know your opinion.

Labels:

  15:00 1 comments
Bookmark and Share
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