Java Spring bean with private constructor

前端 未结 5 1460
终归单人心
终归单人心 2020-12-04 17:49

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.

5条回答
  •  再見小時候
    2020-12-04 18:19

    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.

提交回复
热议问题