Daksharaj kamal
Daksharaj kamal

Reputation: 622

How to add Refresh trigger to a class which is annotated with @ApplicationScope

Right now I have an InitialReferenceLoaderImpl which is annotated by @ApplicationScope and the function is annotated by @PostConstruct, in this class I'm loading my Application Properties from the SQL table, but the problem is, If users change something on Application Properties table, it does not get reflected directly, User needs to restart the server, which I don't want.

I want the user to hit the /refresh URL so that Application Properties can be reloaded.

Sorry for the confusing explanation.

Upvotes: 0

Views: 49

Answers (1)

Daksharaj kamal
Daksharaj kamal

Reputation: 622

I've solved my problem by using Bean.refresh(), The solution I was seeking, was I wanted a /refresh end-point which will refresh my bean to do that I followed the following steps -

  1. I Autowired the ConfigurableApplicationContext
    @Autowired
    private ConfigurableApplicationContext context;

  2. In the endpoint I initialized the bean -
    ReferenceClass bean = context.getBean(ReferenceClass.class);

  3. Refreshed is using .refresh()
    bean.refresh();

That's it, it solved my issue, once the user hits the /refresh endpoint it refreshes my bean.

Upvotes: 0

Related Questions