Correct way of making a singleton a Spring bean

前端 未结 6 808
野性不改
野性不改 2020-12-08 03:12

I am converting a singleton to a Spring bean, so that if the singleton fails to initialize, then entire web application\'s spring context doesn\'t load properly.

Th

6条回答
  •  臣服心动
    2020-12-08 03:25

    According to me this is a belts-and-suspenders solution.

    If you create a bean and declare it as a singleton in the configuration then there should be no need to protect the bean against being multiply created.

    You are now basically protecting yourself from someone wrongly configuring the bean.

    I personally would "solve" that by documentation in the spring configuration and Javadoc.

提交回复
热议问题