Java Spring bean with private constructor

user710818 picture user710818 · Aug 31, 2011 · Viewed 33.1k times · Source

Is possible in Spring that class for bean doesn't have public constructor but only private ? Will this private constructor invoked when bean is created? Thanks.

Answer

Kevin Stembridge picture Kevin Stembridge · Aug 31, 2011

Yes, Spring can invoke private constructors. If it finds a constructor with the right arguments, regardless of visibility, it will use reflection to set its constructor to be accessible.