I am trying to test my controller using JUNIT test cases but finding the below exception
Caused by: java.lang.IllegalStateException: No Scope registered for scope name 'refresh'
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.getTarget(CglibAopProxy.java:705)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
1 The Console shows as below where a message reads as ‘This is the test case in this class’. 2 The JUnit result tab displays mainly the number of test cases run, number of errors and number of failures encountered i.e. ... 3 The time taken to finish the execution of the tests. 4 Displays a green bar if all the test cases are passed. More items...
Putting @RefreshScope on the configuration will indeed refresh the configuration BUT not the beans it created. You need to explicitly define which beans you want to have refreshed. This can be done by either annotating the desired class to be @RefreshScope or the @Bean method to have @RefreshScope.
You need to explicitly define which beans you want to have refreshed. This can be done by either annotating the desired class to be @RefreshScope or the @Bean method to have @RefreshScope. Your understanding is a bit off and all of that is stated in the documentation. From the javadoc of @RefreshScope.
From the javadoc of @RefreshScope. The implementation involves creating a proxy for every bean in the scope, So you will get 2 instances of the bean. 1 Proxy which will actually wrap an full instance of the bean. When being refreshed, the proxy will survice and the actual instance will be replaced.
try to put in your test file:
@ImportAutoConfiguration(RefreshAutoConfiguration.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With