I guess Spring here should also get the instance through reflection and then set the value. If there is no parameterless constructor, there should be an exception when calling newInstance() during reflection.
Please give me some advice from the experts downstairs.
If a Spring bean does not have a default constructor, you need to clearly specify which constructor to use and what parameter values to pass in the configuration.
Spring should be constructed by calling the parameterless constructor, and then use setto set the value and inject. So if you don't set it, you should get an error. It seems that it is not possible to specify a constructor... I am not sure. You can check Spring's API. 设值注入的。所以你不设定应该会报错的。 指定构造器这个事情好像办不到吧...我不太确定,你可以查查Spring的api。
另外 java中大部分项目都采用设值注入的,支持构造器注入
In addition, most projects in Java use set value injection, and those that support constructor injection will generally leave APIs and interfaces for you. 🎜
I guess Spring here should also get the instance through reflection and then set the value.
If there is no parameterless constructor, there should be an exception when calling
newInstance()
during reflection.Please give me some advice from the experts downstairs.
I don’t know what you are talking about...
If a Spring bean does not have a default constructor, you need to clearly specify which constructor to use and what parameter values to pass in the configuration.
Spring should be constructed by calling the parameterless constructor, and then use set
to set the value and inject
. So if you don't set it, you should get an error.It seems that it is not possible to specify a constructor... I am not sure. You can check Spring's API.
设值注入
的。所以你不设定应该会报错的。指定构造器这个事情好像办不到吧...我不太确定,你可以查查Spring的api。
另外 java中大部分项目都采用
In addition, most projects in Java use设值注入
的,支持构造器注入
set value injection
, and those that supportconstructor injection
will generally leave APIs and interfaces for you. 🎜