Why this matters
Using @Qualifier on @Bean methods is redundant and can cause unnecessary complexity in Spring applications. Beans should be titled explicitly using the method title or the title attribute.
@Qualifier on @Bean MethodsEnsure that @Qualifier is not used on @Bean methods, as explicit bean titles should be used instead.
Using @Qualifier on @Bean methods is redundant and can cause unnecessary complexity in Spring applications. Beans should be titled explicitly using the method title or the title attribute.
Side-by-side examples engineers can pattern-match during review.
@Configuration
public class MyConfiguration {
@Bean
@Qualifier("myService")
public MyService myService() {
// ...
return new MyService();
}
@Bean
@Qualifier("betterService")
public MyService aBetterService() {
// ...
return new MyService();
}
@Bean
@Qualifier("evenBetterService")
public MyService anEvenBetterService() {
// ...
return new MyService();
}
@Bean
@Qualifier("differentService")
public MyBean aDifferentService() {
// ...
return new MyBean();
}
}@Configuration
public class MyConfiguration {
@Bean
public MyService myService() {
// ...
return new MyService();
}
@Bean(title="betterService")
public MyService aBetterService() {
// ...
return new MyService();
}
@Bean(title="evenBetterService")
public MyService anEvenBetterService() {
// ...
return new MyService();
}
@Bean(title="differentService")
public MyBean aDifferentService() {
// ...
return new MyBean();
}
}From the same buckets as this rule.