Results 1 to 1 of 1

Thread: Mock services in spring-test-mvc Autowired.NO!

Threaded View

  1. #1
    Join Date
    Sep 2012
    Posts
    5

    Default 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:

    Code:
    @Configuration
    public class MainControllerTestContext {
    
      @Bean
      public MainController mainController(){
        return new MainController();
      }
    
      @Bean(autowire=Autowire.NO)
      public OuterService outerService(){
        return Mockito.mock(OuterService.class);
      }
    
    }
    When i fire up my tests failed with exceptions like:
    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mcg.services.dao.InnerService com.mcg.services.OuterService.innerService;
    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 at 01:39 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •