Use @Named
to differentiate between different objects of the same type bound in the same scope.
@Named("maxWaitTime")
public long maxWaitTimeMs;
@Named("minWaitTime")
public long minWaitTimeMs;
Without the @Named
qualifier, the injector would not know which long to bind to which variable.
If you want to create annotations that act like
@Named
, use the@Qualifier
annotation when creating them.If you look at
@Named
, it is itself annotated with@Qualifier
.
Related Contents:
- What is the difference between @Inject and @Autowired in Spring Framework? Which one to use under what condition?
- What exactly is Spring Framework for? [closed]
- @Resource vs @Autowired
- How can I inject a property value into a Spring Bean which was configured using annotations?
- How to inject dependencies into a self-instantiated object in Spring?
- Difference between @Bean and @Autowired
- ContextLoaderListener or not?
- exclude @Component from @ComponentScan
- How to inject a Map using the @Value Spring Annotation?
- Java EE 6 vs. Spring 3 stack [closed]
- Is it possible to add qualifiers in @RequiredArgsConstructor(onConstructor = @__(@Autowired))?
- Spring: Why do we autowire the interface and not the implemented class?
- Spring JUnit: How to Mock autowired component in autowired component
- Explain why constructor inject is better than other options [duplicate]
- How to get bean using application context in spring boot
- Using Spring 3 autowire in a standalone Java application
- Inject bean into enum
- Self injection with Spring
- What is Dependency Injection? [duplicate]
- Injecting a String property with @InjectMocks
- Is spring default scope singleton or not?
- Spring annotation-based DI vs xml configuration?
- spring @Autowire property vs setter
- Spring Property Injection in a final attribute @Value – Java
- Java Spring: How to use `@Value` annotation to inject an `Environment` property?
- What is Dispatcher Servlet in Spring?
- How to count members with jsonpath?
- Thymeleaf: how to use conditionals to dynamically add/remove a CSS class
- Spring Data JPA findOne() change to Optional how to use this?
- Spring vs EJB. Can Spring replace EJB? [closed]
- @Cacheable key on multiple method arguments
- Spring cron expression for every after 30 minutes
- How to return 404 response status in Spring Boot @ResponseBody – method return type is Response?
- Auto-wiring a List using util schema gives NoSuchBeanDefinitionException
- Spring RedirectAttributes: addAttribute() vs addFlashAttribute()
- What is the best way to return different types of ResponseEntity in Spring-Boot (Error Handling for REST with Spring)
- Set Logging Level in Spring Boot via Environment Variable
- Maven + Spring Boot: Found multiple occurrences of org.json.JSONObject on the class path:
- How to get access to job parameters from ItemReader, in Spring Batch?
- How to enable HTTP response caching in Spring Boot
- Right way to write JSON deserializer in Spring or extend it
- Spring — inject 2 beans of same type
- Spring MVC PATCH method: partial updates
- No Dialect mapping for JDBC type: 1111
- how to show query while using query annotations with MongoRepository with spring data
- How do you turn off swagger-ui in production
- Intellij IDEA: specify datasource for JPA validation
- Creating a post commit when using transaction in Spring
- Why does Hibernate disable INSERT batching when using an IDENTITY identifier generator
- Spring-boot: required a bean named ‘entityManagerFactory’ that could not be found