I want to write the test of this endpoint, but I am getting the following error. How can I make the expression resolve bean ? Using @MockBean MessageSecurityService didn’t work. Answer Have you stub the return of the @MockBean e.g also have you added the following in your test class: