本文介绍了Java具有私有构造函数的Spring bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有可能在Spring中,类的bean没有公共构造函数,但只有私有? 这个私有构造函数在bean创建时调用? 感谢。
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.
推荐答案是的,Spring可以调用私有构造函数。如果它找到具有正确参数的构造函数,则不管可见性如何,它将使用反射将其构造函数设置为可访问。
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.
更多推荐
Java具有私有构造函数的Spring bean
发布评论