Java Reference
In-Depth Information
If everything is fine, you should see the following sequence numbers output, along with some
logging messages that you might not be interested in:
1-2. Configuring Beans in the Spring IoC Container
Spring offers a powerful IoC container to manage the beans that make up an application. To utilize the
container services, you have to configure your beans to run in the Spring IoC container.
You can configure your beans in the Spring IoC container through XML files, properties files,
annotations, or even APIs.
Spring allows you to configure your beans in one or more bean configuration files. For a
simple application, you can simply centralize your beans in a single configuration file. But for a large
application with a lot of beans, you should separate them in multiple configuration files according to
their functionalities. One useful division is by the architectural layer that a given context services.
How It Works
Suppose that you are going to develop an application for generating sequence numbers. In this
application, there may be many series of sequence numbers to generate for different purposes. Each
one of them will have its own prefix, suffix, and initial value. So, you have to create and maintain
multiple generator instances in your application.
Creating the Bean Class
In accordance with the requirements, you create the SequenceGenerator class that has three
properties_ prefix , suffix , and initial _that can be injected via setter methods or a constructor. The
private field counter is for storing the current numeric value of this generator. Each time you call the
getSequence() method on a generator instance, you will get the last sequence number with the prefix
and suffix joined. You declare this method as synchronized to make it thread-safe.
Search WWH ::

Custom Search