img
for the PropertySource abstraction. To instruct Spring to give precedence for the values in the
application.properties file, we add the attribute local-override="true" to the <context:property-
placeholder> tag.
<context:property-placeholder local-override="true"
location="classpath:env/application.properties"/>
The local-override attribute instructs Spring to override the existing properties with the properties
defined in this placeholder. Run the program, and you will see that now the user.home property from the
application.properties file was retrieved.
application.home: /etc/prospring3/home
user.home: /clarence/home
From the previous two sections, you can see that profiles and property source abstraction by the
Environment interface in Spring 3.1 give us a powerful and centralized way to manage the configurations
of the application environment.
Configuration Using JSR-330 Annotations
As we discussed in Chapter 1, JEE 6 provides support for JSR-330 (Dependency Injection for Java), which
is a collection of annotations for expressing an application's DI configuration within a JEE container or
other compatible IoC framework. Spring also supports and recognizes those annotations, so although
you're not running your application in a JEE 6 container, you can still use JSR-330 annotations within
Spring. Using JSR-330 annotations can help you ease the migration to the JEE 6 container or other
compatible IoC container (e.g., Google Guice) away from Spring.
Again, let's take the message renderer and message provider as an example and implement it using
JSR-330 annotations.
To support JSR-330 annotations, you need to add a dependency to the project, as shown in Table 5-5.
Table 5-5. Dependency for JSR-330 Support
Group ID
Artifact ID
Version
Description
1
JSR-330 standard library
javax.inject
javax.inject
The interface classes (MessageRenderer and MessageProvider) are the same, so we'll save some space
and not list them. Listing 5-65 shows the implementation of ConfigurableMessageProvider.
Listing 5-65. ConfigurableMessageProvider (JSR-330)
package com.apress.prospring3.ch5.jsr330;
import javax.inject.Inject;
import javax.inject.Named;
@Named("messageProvider")
public class ConfigurableMessageProvider implements MessageProvider {
private String message = "Default message";
public ConfigurableMessageProvider() {
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home