Search code examples
javaspringspring-bootspring-cloudspring-cloud-config

Bean with RefreshScope in Pojo in Spring boot


I am new to Spring boot, what I am having in my project is a Configuration Class annotated with RefreshScope and the same is used in a Pojo Class and a copy is stored in local variable inside constructer.

Please suggest how to refresh that local variable in Pojo Class

Code is as below

  1. Configuration Class
    @Configuration
    @Getter
    @RefreshScope
    public class ProjectSetting {
    
        @Value("${security.enabled:true}")
        private boolean securityEnabled;
    
      
    }
  1. Pojo Class
public class AssetTaggingEventProcessor
{
   private ProjectSetting projectSetting;
   AssetTaggingEventProcessor()
   {
         projectSetting = applicationContext.getBean(ProjectSetting.class);
   }
}

Solution

  • Thanks @M.Deinum, It worked as you mentioned in comments, moreover I found detail explanation also on other posts that There will be a new proxy object will be prepared and then it will be replaced with actual object to Pojo will have reference to new object.