you see fit, using getFile(), getInputStream(), or getURL(). In some cases, such as when you are using
the http: protocol, the call to getFile() results in a FileNotFoundException. For this reason, we
recommend that you use getInputStream() to access resource contents because it is likely to function
for all possible resource types.
Configuration Using Java Classes
Besides XML configuration, you can also use Java classes to configure Spring's ApplicationContext.
Spring JavaConfig used to be a separate project, but starting with Spring 3.0, its major features for
configuration using Java classes was merged into the core Spring Framework.
In this section, we will take a look at how to use Java classes to configure a Spring's
ApplicationContext and its equivalent when using XML configuration.
ApplicationContext Configuration in Java
Let's see how we can configure Spring's ApplicationContext using Java classes, by referring to the same
example for message provider and renderer that we presented in Chapter 4. Listing 5-42 recaps the
message provider interface and a configurable message provider.
Listing 5-42. MessageProvider and ConfigurableMessageProvider
package com.apress.prospring3.ch5.javaconfig;
public interface MessageProvider {
public String getMessage();
}
package com.apress.prospring3.ch5.javaconfig;
public class ConfigurableMessageProvider implements MessageProvider {
private String message = "Default message";
public ConfigurableMessageProvider() {
}
public ConfigurableMessageProvider(String message) {
this.message = message;
}
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home