Jade Tang
Jade Tang

Reputation: 319

Spring refresh context performance consideration

I am trying to use @RefreshScope annotation in my project, but I am not sure during the refresh, my application will freeze or not. I do not find any document about it in the web. Any thoughts is welcomed.

Upvotes: 0

Views: 925

Answers (1)

churchinvirus
churchinvirus

Reputation: 41

I found below article helpful in understanding how RefreshScope works. A quote from the same:

If you declare a @Bean having this scope, Spring Cloud will wrap that bean in a proxy class, which is what other components will actually get injected with. This proxy will just be proxying every method of the component to the real implementation.

Whenever there is a refresh event in the application, all the RefreshScope proxy beans will mark their underlying bean (the real implementation) as dirty. This means that whenever any of the methods of the proxy are called, it will first re-create the underlying bean, and then it will forward the method call. This re-creation of the bean would mean that it reads the configuration again. It’s important to make sure that @RefreshScope beans are lightweight, since refresh events will trigger re-construction of these beans.

https://dzone.com/articles/spring-cloud-config-series-part-1-introduction

Upvotes: 2

Related Questions