0

I need some help regarding spring re-initialization of component

I am currently using following in my DAO

@Autowired
ScopeTest scopeTest;

and model as -

@Component
    public class ScopeTest{

    private String  scopeId ;                        // STRING(60),
    private String  scopeType;                        //    STRING(60),
}

the issue i am facing is, while tesing if the type is null the new response is keep showing me older value. It seems that the component need to re initlize on every request/responce session but help me what is the right solution

Dalton Cézane
  • 3,672
  • 2
  • 35
  • 60
  • When "tesing if the type is null" which type do you refer to? And which response? It's not clear from the question. – Boris Sep 24 '18 at 16:52

2 Answers2

0

"re-initialization of component"

Default scope of bean is singleton in spring, so it won't not change after creating.

You might want to use the different scope like "Prototype"

For more control about the bean, you can create the bean Dynamically.

Huy Nguyen
  • 1,931
  • 1
  • 11
  • 11
  • It worked, However it caused the issue with resources, do you know how to destroy the bean after completion of json response – Anupam Sharma Sep 25 '18 at 17:36
  • Take a look instruction here: https://stackoverflow.com/questions/6855811/how-can-i-remove-a-singleton-spring-bean-from-applicationcontext – Huy Nguyen Sep 26 '18 at 03:29
-1
  • Problem is with your DAO layer only, call new method with @Query then it may return you newly updated data.