0

What happens to the object I return from an @Bean method? Is there anyway to retrieve this object from another class?

Artanis
  • 561
  • 1
  • 7
  • 26
  • Bean(s) are class instances managed by the Spring context. By managed, I mean Spring manage their entire lifecycle. You can for example listen for lifecycle events by using the PostConstruct or PreDestroy annotation. To interact with Bean(s) you need to Autowire them inside other Bean(s), via constructor injection, setter injection, or property injection. Bean(s) might be of different scopes, such as Prototype (an instance gets created for each Autowire), Singleton (only one instance will ever exist), Session or Request. – LppEdd Feb 14 '19 at 22:29
  • It's now a "Spring bean" in the context; usually, you just say that you need it (such as by putting it in a constructor or `@Bean` method argument) and Spring takes care of finding it for you. – chrylis -cautiouslyoptimistic- Feb 14 '19 at 22:33

0 Answers0