Spring By default, controllers should be handled by default, this is true. However, this does not mean that your value will be canceled on the next call. From the point of view of programmers, this is not permissible if in the end you get the same instance of your controller or another instance. In addition, Iβm no longer sure that no one else used the controller (and therefore changed its state in the meantime). This is why it is not recommended to save any state at all in the fields of your controller. Perhaps you should reconsider the need for a field in your controller.
Actually there is an init method for spring beans. You can simply annotate the public void method on your controller with @PostConstruct . This method is executed after the dependencies are entered . Thus, this method is called exactly after creating the controller instance.
As far as I understand your question, you are looking for some method that is executed before each method call of your controller. In this case, you can simply call your init method at the beginning of each of your controller methods . If you do not want to make this explicit in your AOP code, you can choose an alternative.
source share