Search code examples
javaspringspring-framework-beans

@Bean(autowire = Autowire.BY_TYPE) is deprecated. What would be alternative?


In sonarqube, I get code smell for using @Bean(autowire = Autowire.BY_TYPE) inside my Bean class. I checked the Spring documentation and this information is also mentioned there. However I do not see the alternative for this.

Could anyone please help to remove this code smell?


Solution

  • The autowire option now does nothing, so just remove it.

    As the docs say:

    Deprecated as of 5.1, since @Bean factory method argument resolution and @Autowired processing supersede name/type-based bean property injection