Java Reference
In-Depth Information
package com.apress.springenterpriserecipes.sequence;
public class SequenceGenerator {
private String prefix;
private String suffix;
private int initial;
private int counter;
public SequenceGenerator() {}
public SequenceGenerator(String prefix, String suffix, int initial) {
this.prefix = prefix;
this.suffix = suffix;
this.initial = initial;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public void setInitial(int initial) {
this.initial = initial;
}
public synchronized String getSequence() {
StringBuffer buffer = new StringBuffer();
buffer.append(prefix);
buffer.append(initial + counter++);
buffer.append(suffix);
return buffer.toString();
}
}
As you see, this SequenceGenerator class can be configured by getters/setters or by the constructor.
When configuring them with the container, this is called constructor injection and setter injection.
Creating the Bean Configuration File
To declare beans in the Spring IoC container via XML, you first have to create an XML bean
configuration file with an appropriate name, such as beans.xml . You can put this file in the root
of the classpath for easier testing within an IDE.
The Spring configuration XML allows you to use custom tags from different schemas ( tx , jndi , jee ,
and so on) to make the bean configuration simpler and clearer. Here's an example of the simplest XML
configuration possible.
Search WWH ::




Custom Search