title: Spring Profiles not recognized in a Web Application
body: <p>I'm trying to implement Spring Profiles to load a specific class implementation based on the profile specified. The profile to use is specified as a property (spring.profiles.active) within a properties file included in the classpath.</p>
  
  <p>Source here: <a href="https://github.com/overattribution/spring-profile-test" rel="nofollow">https://github.com/overattribution/spring-profile-test</a></p>
  
  <pre><code>public interface MyService {
      public void doSomething();
  }
  
  @Service
  @Profile("preprod")
  public class MyServicePreProdImpl implements MyService {
      private final Logger LOG = LoggerFactory.getLogger(MyServicePreProdImpl.class);
      @Override
      public void doSomething() {
          LOG.debug("Doing something in " + MyServicePreProdImpl.class.getName());
      }
  }
  
  @Service
  @Profile("prod")
  public class MyServiceProdImpl implements MyService {
      private final Logger LOG = LoggerFactory.getLogger(MyServiceProdImpl.class);
      @Override
      public void doSomething() {
          LOG.debug("Doing something in " + MyServiceProdImpl.class.getName());
      }
  }
  </code></pre>
  
  <p>However, I'm getting the following error:
  No qualifying bean of type [com.example.profileservice.MyService] found for dependency.</p>
  
  <p>What am I missing?</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>I'm manually setting the active profile during web application initialization, but I'm still getting the "No qualifying bean found" error. Changes can be seen here: <a href="https://github.com/overattribution/spring-profile-test/commit/09175a10b28ea8e5a08b43ad1416431bcf094c9d" rel="nofollow">https://github.com/overattribution/spring-profile-test/commit/09175a10b28ea8e5a08b43ad1416431bcf094c9d</a></p>