Search code examples
javaspringspring-bootsingletonspring-ioc

use @value in non-bean class in spring boot


I am working on spring boot project.I create a singleton class in my spring boot application.I wanna get properties from application.properties in my singleton class.is it possible in non-bean class?How to do?


Solution

  • Every Spring bean is singleton scope by default. Therefore you should not use Java singleton class pattern in Spring driven application, just use spring bean and inject @Value there.