79079810

Date: 2024-10-11 22:09:21
Score: 2
Natty:
Report link

I just want to add a specific edge case where certain components are preferable to be configured as @Bean's rather than @Component, @Service

One such scenario is when doing @WebMvcTest for testing authentication. Because @WebMvcTest auto configures Spring security if it is found on the classpath, but then because certain custom beans declared as @Service, will not be picked up by component scanning.

If I declare it as a @Bean in a config file, it can just be imported inside and used around

Reasons:
  • No code block (0.5):
  • User mentioned (1): @Bean's
  • User mentioned (0): @Component
  • User mentioned (0): @Service
  • User mentioned (0): @WebMvcTest
  • User mentioned (0): @WebMvcTest
  • User mentioned (0): @Service
  • User mentioned (0): @Bean
  • Low reputation (0.5):
Posted by: theMyth