开发者

Spring Bean Configuration: How to mark beans as mandatory/optional?

开发者 https://www.devze.com 2023-01-18 09:09 出处:网络
I am making heavy use of Springs XML Configuration for Java Beans. Is there a best practice to mark a property of a bean as optional or required? I am currently initializing the optional beans in the

I am making heavy use of Springs XML Configuration for Java Beans. Is there a best practice to mark a property of a bean as optional or required? I am currently initializing the optional beans in the default constructor. If one of the required properties it not set in most cases a NullPointerException will be thrown, but that doesn't really seem to be a good solution.

开发者_如何学编程Sincereley, Heinrich


There is the @Required annotation that you can use on mandatory fields.


You can set bean lazy which are not frequently required , they will be initilized only when they actually needed.

Doc

0

精彩评论

暂无评论...
验证码 换一张
取 消