Monday, December 31, 2012

Spring Java-based configuration

From Spring 3.0, we can configure our Spring application with a new way: Java-based configuration. With Java-based configuration, you can migrate all XML configuration files to configuration Java class. With that, you can avoid typing errors and enjoy the programmatic features. Though some IDEs, like Intellij IDEA can make you away from typing errors, but with Java-based configuration, you can enjoy this feature on all of IDEs, even with text editors.

In my opinion, Spring configuration best practice is use Annotation configure your own code. For 3rd party classes, Java-based configuration is a good choice.

The following are some samples from Spring 3.0 Documentation.

XML-based configuration load Java-based configuration
Java-based configuration load XML-based configuration
Specifying bean scope