Recommended Free Tools
Spring annotations add metadata that Spring’s IoC container processes to register beans, configure them, inject dependencies, and decide which definitions are eligible in a given environment. They are not self-executing: the relevant application context must have the infrastructure that processes them, and the annotated class or method must participate in that context.
What Spring annotations do
Annotations describe how Spring should handle a class, method, or field. Spring’s reference documentation explains that annotation-based configuration operates on metadata attached to those declarations: Annotation-based Container Configuration.
The container’s processing infrastructure reads that metadata. As a result, an annotation on an ordinary object that Spring does not manage will not, by itself, make that object a bean or inject its dependencies. In XML-based applications, for example, <context:annotation-config/> registers relevant post-processors; it applies to beans in the same application context where the element is declared, not automatically to every context in the application.
The examples below focus on core container annotations. Spring has many others in areas such as web applications, transactions, testing, data, and integration.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
How beans are declared: @Component, @Bean, and @Configuration
Spring offers two common routes to a bean definition: discover an annotated class, or explicitly declare a factory method. Choose based on where the object comes from and how much control its construction needs.
| Approach | What it declares | Typical fit |
|---|---|---|
@Component |
A class marked for discovery through component scanning. | A class in your application that Spring should find and manage. |
@Bean |
A method whose returned object is managed by the Spring IoC container. | Explicit construction or configuration, including cases where the class itself is not annotated, such as a third-party type. |
@Configuration |
A class used primarily as a source of bean definitions, commonly through @Bean methods. |
A central place to declare application beans in Java configuration. |
Discover a class with @Component
@Component marks a class as a candidate for registration through component scanning. Scanning must be configured for the relevant package and application context; placing the annotation on a class alone does not guarantee that Spring will discover it.
Declare a factory method with @Bean
Annotate a method with @Bean to register the object it returns as a managed bean. The Spring reference defines it as an annotation indicating that a method “instantiates, configures, and initializes a new object to be managed by the Spring IoC container”: Basic Concepts: @Bean and @Configuration.
By default, the method name is the bean name. For example:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute@Configuration
class ServiceConfig {
@Bean
PaymentGateway paymentGateway() {
return new PaymentGateway();
}
}
Here, the returned PaymentGateway is registered under the name paymentGateway, unless a different name is specified.
Understand full configuration and method-call behavior
A regular @Configuration class is enhanced by Spring so that one @Bean method calling another can receive the container-managed bean rather than create an unmanaged object through an ordinary Java call. This behavior relies on class enhancement; configuration classes must not be final. See Using the @Configuration annotation.
Setting @Configuration(proxyBeanMethods = false) disables that method-call interception. A plain @Component class can also declare @Bean methods, but calls between those methods are not intercepted in the same way. If one bean needs another in these cases, express the dependency through method parameters or dependency injection instead of relying on a direct call between factory methods.
How @Autowired injects dependencies
@Autowired asks Spring to resolve a dependency against eligible beans in the container. It can be used on constructors, methods, and fields; constructor injection is a practical choice for required collaborators because it makes those requirements explicit when the object is created. That is a design recommendation, not a requirement imposed by the annotation.
Rank #3
When only one eligible bean matches the requested type, Spring can inject it. If several beans match, use candidate-selection metadata to resolve the ambiguity. Spring’s guidance on dependency injection is in Autowiring Collaborators.
Use @Primary for a default preference
Mark one bean @Primary when it should be preferred for a single-valued dependency if multiple candidates match. It establishes a default preference, rather than naming a particular choice at every injection point. If more than one primary candidate exists for the dependency, the annotation does not resolve the ambiguity by itself.
Use @Qualifier to narrow a particular injection point
Use @Qualifier when an injection point needs a specific kind of candidate. Spring first considers type-compatible beans, then uses qualifier metadata to narrow the set; a qualifier is not merely a global lookup by bean name. For example:
@Component
class CheckoutService {
private final PaymentGateway gateway;
CheckoutService(@Qualifier("online") PaymentGateway gateway) {
this.gateway = gateway;
}
}
The qualifier value identifies matching qualifier metadata among type-compatible candidates. See Fine-tuning Annotation-based Autowiring with Qualifiers.
| Annotation | Selection effect | Use it when |
|---|---|---|
@Primary |
Prefers one bean as the default for a single-valued dependency. | One implementation should normally win wherever the type is injected. |
@Qualifier |
Narrows type-compatible candidates at an injection point. | A particular dependency needs a specifically qualified implementation. |
@Fallback |
Marks a bean to lose to regular candidates when they are available. | A backup implementation should be used only when no regular candidate is available. |
@Fallback is documented as available as of Spring Framework 6.2. Parameter or field names can also participate in resolving some non-unique dependencies when no other resolution indicator applies; consult the reference for the Framework version in use, since this behavior is version-sensitive.
For full details on primary and fallback candidates, see Fine-tuning Annotation-based Autowiring with @Primary or @Fallback.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What @Profile does
@Profile makes a component, configuration class, or individual @Bean method eligible for registration only when its profile condition matches the active environment. It affects whether a bean definition is registered; it does not inject a property value into a bean that is already registered.
A class-level profile applies to its bean methods and imports. A method-level profile is useful for selecting among alternative bean definitions. Profile expressions support negation (!), AND (&), and OR (|); use parentheses when combining AND and OR so the intended grouping is clear. See Environment Abstraction.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Best Value
Values and lifecycle annotations
@Value is commonly used to inject a value into a bean. It is distinct from @Profile: profile conditions control whether a definition is eligible, while value injection supplies data to a registered bean. The exact placeholder, expression, and conversion behavior depends on the application’s configuration and Framework version, so check the matching version’s reference before relying on specific resolution rules.
Spring also supports Jakarta lifecycle annotations @PostConstruct and @PreDestroy, as well as Jakarta Inject annotations such as @Inject and @Named, through its annotation-processing infrastructure. In current code, use the jakarta.* package names rather than treating the older javax.* names as the default. The relevant support is covered in Annotation-based Container Configuration.
Check these points when an annotation appears not to work
- Is the object managed? Annotation processing applies to beans in the relevant application context, not arbitrary objects created outside it.
- Is processing enabled in that context? Confirm component scanning or the appropriate annotation configuration infrastructure is active where the bean is defined.
- Does the bean qualify? Check type compatibility, qualifier metadata, primary/fallback status, and any ambiguity at the injection point.
- Is the profile active? A profile-conditional definition may not be eligible in the current environment.
- Does configuration rely on intercepted method calls? Calls between
@Beanmethods are not intercepted in plain components or whenproxyBeanMethods = false.
Documentation versions linked here include Spring Framework 7.0 reference pages and 7.1 development pages; the 7.1 links identify development documentation, not a claim that every behavior is available in every release. The @Fallback reference explicitly dates its availability to Framework 6.2. Match the documentation and annotation behavior to the Framework version your application uses.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

