title: store state of value to avoid multiple calls and not pass as parameter
body: <p>In my spring mvc application, Trying to refactor the code to avoid multiple calls to a method.</p>
  
  <pre><code>@RestController
  Class A{
  
  @Autowired
  Service1 service1
  
  @Autowired
  Service2 service2
  
  @RequestMapping(value = "/****/***", method = RequestMethod.GET)
  aMethod(){
  
      service1.service1Method(a,b)
  
      service2.service2Method1(a,b)
  
      service2.service2Method2(a,b)
  
  }
  
  @Component
  class Service1{
  
      service1Method(a,b)
      {
          String someValue = util.utilMethod();
      }
  
  }
  @Component
  class Service2{
  
      service2Method1(a,b)
      {
          String someValue = util.utilMethod();
      }
  
      service2Method2(a,b)
      {
          String someValue = util.utilMethod();
      }
  }
  @Component
  class Util
  {
      String utilMethod()
      {
          return "something"
      }
  }
  </code></pre>
  
  <p>The <code>utilMethod()</code> calls three time, to get a value.Here trying to avoid the multiple calls and can handle by one.</p>
  
  <p>I can call utill method in controller and pass the value as a third parameter.Like this.</p>
  
  <pre><code>@Autowired
  Service1 service1
  
  @Autowired
  Service2 service2
  
  @Request
  aMethod(){
  
      String someValue = util.utilMethod();
  
      service1.service1Method(a,b,someValue)
  
      service2.service2Method1(a,b,someValue)
  
      service2.service2Method2(a,b,someValue)
  
  }
  </code></pre>
  
  <p>But don't want to do like this.because lot of code changes are required.
  Is there any way I can store the value in (but not request, session) controller and can get service1 and service2 classes.</p>