Scope of @Configuration Class in spring

随声附和 提交于 2020-08-09 05:27:17

问题


We are having @Configuration class, but it doesn't contain any bean definition and as it is a legacy class written by someone i don't want to remove the @Configuration annotation even while there is no bean definition. Somehow i want to perform logic on shutdown hook of web application but somehow i am not able to get bean from context in the contextDestroyed() method so i want to use @PreDestroy on that @Configuration class.

Does any one specify what is the default scope of the @Configuration class. As I don't want that if the scope is non-singleton that bean would the @PreDestroy will be called again and again.


回答1:


@Configuration is meta-annotated with @Component. This is where its Scope rules are derived from. @Scope-annotated components that specify no value (and those without a Scope annotation for that matter) default to Singleton Scope as can be looked up in the respective JavaDoc.



来源:https://stackoverflow.com/questions/34016964/scope-of-configuration-class-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!