Archive for the 'Spring' Category

Simple Spring trick - Splitting config files

The application that I am working on at work uses Spring fairly heavily for its configuration. One problem that we have is that we don’t want to expose the config file, but we need to expose the data source part of it. We are configuring Hibernate through Spring which requires us to put the data source information in the Spring config file; we needed a way to split the config file so that data source part could exist outside the jar file.

This actually proved really easy to do, trivial actually, but I will post the method for other newbies, like me, who may stumble upon this blog.

Basically, you split the file into two complete Spring configuration files and then import the one into the other. There are two keys to remember when doing this: 1) both files must be complete config xml files that validate against the Spring schema and 2) the path used when importing is relative to the parent file so the two files must be in the same directory or on the same classpath.

Here is the code to use (shortened for brevity):


  

  

There is one more rule that you must remember. You have to reference the beans in the imported file using <ref bean="bean id"/> instead of <ref local="my bean"/> because the @local@ attribute is scoped to the physical file in which it appears. Also, you need to import files before referencing any beans in the imported file (this is probably obvious though).

Simple, eh? I love Spring.

Spring 2.0 released

“Spring 2.0 was released today”:http://www.theserverside.com/news/thread.tss?thread_id=42460. For more info, read the link. I guess the real question that should be asked is whether it makes sense to upgrade or wait for the first Spring 2.0 books to come out and show us how it should be done.

“The link to the actual article on the Spring website”:http://www.springframework.org/go-2.0.

Working with Spring 2.0 in JDeveloper

Oracle has a very thorough tutorial on how to work with “Spring 2.0 in JDeveloper”:http://www.oracle.com/technology/products/jdev/howtos/1013/SpringwithJDev/index.html.

bq. In this article we’ll show you how to set up JDeveloper to use the Spring framework, and then highlight some of the functionality in JDeveloper that can make your development experience with Spring more productive.

Ten Common Misconceptions About Spring… - O’Reilly ONJava Blog

O’Reilly’s ONJava website has an article on Ten Common Misconceptions About Spring that is worth checking out. It does a good job of answering some myths about Spring and clearing out the FUD.

bq. For those new to the Spring Framework, we feel as though it is necessary to address some of the concerns you may have when approaching Spring for the first time. In fact, we have compiled this list based on our collective experience in training new Spring users and observing discussions and forums throughout the Java development community. It is our goal to shed some light on these issues so that you will be better equipped to make well-informed decisions regarding the adoption of Spring on your next project.