Announcement Announcement Module
No announcement yet.
Mock services in spring-test-mvc Autowired.NO! Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mock services in spring-test-mvc Autowired.NO!

    I am trying to use spring-mvc-test framework to test my controller (name it MainController).
    MainController has injected one service (OuterService) witch i want to mock in standolone test configuration. That service conteins another service as autowired field.

    For my tests i am using context in java class witch looks like:

    public class MainControllerTestContext {
      public MainController mainController(){
        return new MainController();
      public OuterService outerService(){
        return Mockito.mock(OuterService.class);
    When i fire up my tests failed with exceptions like:
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private;
    When i am using interfaces for that services it is everything ok. But i do not want to (I will have one and only one service with interface like this, so implementing interfece is useless).

    How to solve that problem... ?

    Thanks in advance!
    Last edited by damian0o; Oct 4th, 2012, 01:39 AM.