concept bean in category spring

This is an excerpt from Manning's book Spring in Action, Sixth Edition.
At its core, Spring offers a container, often referred to as the Spring application context, that creates and manages application components. These components, or beans, are wired together inside the Spring application context to make a complete application, much like bricks, mortar, timber, nails, plumbing, and wiring are bound together to make a house.
The act of wiring beans together is based on a pattern known as dependency injection (DI). Rather than have components create and maintain the lifecycle of other beans that they depend on, a dependency-injected application relies on a separate entity (the container) to create and maintain all components and inject those into the beans that need them. This is done typically through constructor arguments or property accessor methods.
Figure 5.1. The Spring environment pulls properties from property sources and makes them available to beans in the application context.
![]()
The beans that are automatically configured by Spring Boot are all configurable by properties drawn from the Spring environment. As a simple example, suppose that you would like the application’s underlying servlet container to listen for requests on some port other than the default port of 8080. To do that, specify a different port by setting the
server.portproperty in src/main/resources/application.properties like this:

This is an excerpt from Manning's book Spring Boot in Action.
In any given Spring application’s source code, you’ll find either Java configuration or XML configuration (or both) that enables certain supporting features and functionality for the application. For example, if you’ve ever written an application that accesses a relational database with JDBC, you’ve probably configured Spring’s JdbcTemplate as a bean in the Spring application context. I’ll bet the configuration looked a lot like this:
As it turns out, the auto-configuration that enables the Actuator also creates an instance of CounterService and registers it as a bean in the Spring application context. CounterService is an interface that defines three methods for incrementing, decrementing, or resetting a named metric, as shown here:
package org.springframework.boot.actuate.metrics; public interface CounterService { void increment(String metricName); void decrement(String metricName); void reset(String metricName); }Actuator auto-configuration will also configure a bean of type GaugeService, an interface similar to CounterService that lets you record a single value to a named gauge metric. GaugeService looks like this:
![]()
Listing 7.1 is an abridged listing of the beans from the reading-list application. As you can see, all of the bean entries carry five pieces of information about the bean:
bean—The name or ID of the bean in the Spring application context
Whereas the /beans endpoint produces a report telling you what beans are in the Spring application context, the /autoconfig endpoint might help you figure out why they’re there—or not there.

This is an excerpt from Manning's book Spring Dynamic Modules in Action.
Despite the benefits of the Spring Framework described in section 1.2, it suffers from several drawbacks in particular use cases. The first one occurs when trying to scale up to large and complex applications. In this case, a lot of beans need to be configured within the Spring container, making its configuration more difficult to maintain. In addition, Spring suffers from a lack of modularity and provides no real support to improve this. For example, there’s no way to limit the visibility of a bean in Spring; any other bean can use it, and it can be looked up from the application context even if it should not be used directly. Although you can divide your configuration into several XML files, they all serve to configure a single application context, and the alternative—integrating several Spring containers—can be difficult to achieve. (Using more than one application context could allow you to split an application into modules more easily, creating clearer boundaries between these modules.)
Another limitation of Spring is the static nature of its dependency graph configured using dependency injection. As soon as bean A is injected into bean B, bean B depends on A. An application may have hundreds of beans, and these dependencies between beans form a dependency graph. The limitation arises because the links between beans are created once, mainly at the startup of the container, and there is no built-in support to update them at runtime. To reload the dependency graph and take any updates into account, the whole application needs to be restarted.
This problem of static coupling is made worse by issues with the instantiation order of beans. Spring computes a complex dependency graph to determine the order in which beans will be instantiated and injected. This computation is internal to Spring, and application developers can’t get their hands on it. If something goes wrong, debugging can be particularly complex, especially when you have a lot of dependencies. Furthermore, there is very limited support for circular dependencies, putting an even heavier burden on developers to configure their beans correctly.
In this chapter, we’ll cover how we can globally configure Spring DM’s extenders through fragment-based configuration. For the standard extender, settings range from thread management to the systematic registration of beans in Spring application contexts that Spring DM manages. The web extender also has its own settings that we can leverage; for example, to switch from one embedded web container to another. We’ll also introduce the OSGi security model and see how Spring DM can be integrated into a secured OSGi container.
A fragment can contain several XML files or there can be several fragments. The target extender will search in its bundle space for all the .xml files in its META-INF/ spring/extender directory and will bootstrap an application context from them. This implies that the composition of these files must define a consistent application context (consistent dependencies, no collision for the names of the beans, and so on). Figure 9.1 illustrates the fragment-based configuration of the extender in Spring DM.
Table 9.1 lists the beans that Spring DM’s standard extender recognizes.
Table 9.1. Beans in Spring DM’s extender available for overriding
Bean name
Type
Description
taskExecutor TaskExecutor [[a]] Manages threads and execution for the creation of Spring application contexts shutdownTaskExecutor TaskExecutor [a] Manages threads and execution for the destruction of Spring application contexts extenderProperties Properties [[b]] Defines simple properties related to the extender osgiApplicationEventMulticaster OsgiBundleApplicationContextEventMulticaster [[c]] Propagates OSGi application contexts’ events to interested parties applicationContextCreator OsgiApplicationContextCreator [[d]] Allows customization of the creation of application contexts Any bean name (only the type matters) OsgiBeanFactoryPostProcessor [d] Allows systematic processing of application contexts osgiApplicationContexlistener OsgiBundleApplicationContextListener [c] Allows registration of a global application context listener