Java Reference
In-Depth Information
package com.apress.springenterpriserecipes.sequence;
import javax.annotation.Resource;
public class SequenceGenerator {
@Resource(name = "datePrefixGenerator")
private PrefixGenerator prefixGenerator;
...
}
1-5. Scanning Components from the Classpath
Problem
In order for the Spring IoC container to manage your components, you declare them one by one in the
bean configuration file. However, it can save you a lot of work if Spring can automatically detect your
components without manual configuration.
Solution
Spring provides a powerful feature called component scanning . It can automatically scan, detect, and
instantiate your components with particular stereotype annotations from the classpath. The basic
annotation denoting a Spring-managed component is @Component . Other more particular stereotypes
include @Repository , @Service , and @Controller . They denote components in the persistence, service,
and presentation layers, respectively.
How It Works
Suppose you are asked to develop your sequence generator application using database sequences,
and store the prefix and suffix of each sequence in a table. First, you create the domain class Sequence
containing the id , prefix , and suffix properties.
package com.apress.springenterpriserecipes.sequence;
public class Sequence {
private String id;
private String prefix;
private String suffix;
// Constructors, Getters, and Setters
...
}
 
Search WWH ::




Custom Search