Java具有私有构造函数的Spring bean [英] Java Spring bean with private constructor

查看:945
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆