java - @WebMvcTest giving 'Error creating bean with name' error for different service in spring boot test -


i trying write test spring boot application. independent controller test, have used @webmvctest ran issues. here basic structure of code.

usercontroller has userservice class autowired.

librarycontroller has libraryservice class autowired.

here code usercontrollertest ::

@runwith(springrunner.class) @webmvctest(usercontroller.class) public class usercontrollertest {    @autowired    private mockmvc mockmvc;     @mockbean     private userservice userservicemock;     @test    public void sometest(){}  } 

it giving error while running code in usercontrollertest:

caused by: org.springframework.beans.factory.unsatisfieddependencyexception: error creating bean name 'librarycontroller': unsatisfied dependency expressed through field 'libraryservice'; nested exception org.springframework.beans.factory

as per understanding, since have specified usercontroller inside @webmvctest annotation, need mock dependency required controller. asking libraryservice have no links usercontroller.

and yeah if include library service mockbean inside test, works fine. if case have mock each , every autowired beans program scales.

any explanation appreciated. in advance.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -