问题
I want to unit test an @Controller
-annotated class, using JUnit.
Is it possible for Spring to reset ("re-wire") the controller to its default injected state ? There would be no problem building a all new controller object.
A workaround I found is to set the constructor's visibility to protected and execute ControllerObj controllerObj = new ControllerObj()
at the beginning of @Before
-annotated class but I obviously do not want to increase contructor's visibility just for testing purpose.
回答1:
As suggested by @mate00 the solution was to use the @DirtiesContext
annotation.
来源:https://stackoverflow.com/questions/58390044/re-wire-spring-bean-in-before-method