title: Error creating bean in JUnit test in Spring Boot
body: <p>I am creating application in Spring Boot. I created service that looks that way:</p>
  
  <pre><code>@Service
  public class MyService {
  
      @Value("${myprops.hostname}")
      private String host;
  
      public void callEndpoint() {
          String endpointUrl = this.host + "/endpoint";
          System.out.println(endpointUrl);
      }
  }
  </code></pre>
  
  <p>This service will connect to REST endpoint to other application (developed also by me) that will be deployed along. That is why I want to customize hostname in application.properties file (-default, -qa, -dev).</p>
  
  <p>My application builds and works just fine. I tested it by creating controller that calls this service, and it populates <code>host</code> field with correct property  from application.properties.</p>
  
  <p>The problem occurs when I try to write test for this class.
  When I try this approach:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  public class MyServiceTest {
  
      @Autowired
      private MyService myService;
  
      @Test
      public void callEndpoint() {
          myService.callEndpoint();
      }
  }
  </code></pre>
  
  <p>i receive exception:</p>
  
  <p><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.ge.bm.wip.comp.processor.service.MyServiceTest': Unsatisfied dependency expressed through field 'myService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ge.bm.wip.comp.processor.service.MyService' available: expected at least 1 bean which qualifies as autowire candidate.</code></p>
  
  <p>And some more nested exception. I can post them if it will help.
  I suppose that for some reason SpringRunner does not launch this test in Spring context and therefore cannot see bean MyService. </p>
  
  <p>Does anyone know how it can be fixed? I tried normal initialization:</p>
  
  <pre><code>private MyService myService = new myService();
  </code></pre>
  
  <p>but then <code>host</code> field is <code>null</code></p>