0

When I reference the bean from the constructor it is null, but when referenced from another method it is fine.

balu
  • 41
  • 1
  • 6
  • 1
    You'd really benefit from providing some more details. Any code you can share? – johnnyRose Aug 08 '15 at 01:27
  • Possible duplicate of http://stackoverflow.com/questions/6335975/autowired-bean-is-null-when-referenced-in-the-constructor-of-another-bean tldr: try using @PostConstruct if you need access to beans during class initialization – lux Oct 01 '15 at 15:47

1 Answers1

0

To refer a bean in a constructor, you need to

  1. Annotate the constructor with @Autowired
  2. Pass the bean as a parameter to the constructor

More details can be diagnosed if you share some sample code.

Sanjay
  • 8,755
  • 7
  • 46
  • 62