title: Spring Boot App deployed in Tomcat : Quartz Scheduler bean is not visible from @Service
body: <p>Using Spring Java Config, the scheduler bean is not visible when loading my war packaged app into a tomcat 7.</p>
  
  <p>This configuration was working in another test app...
  How can I point whats wrong ?</p>
  
  <p>Catalina output :</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.quartz.Scheduler fr.myapp.schdtool.service.SchedulerService.scheduler; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.quartz.Scheduler] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
      ... 90 more
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.quartz.Scheduler] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
      ... 92 more
  </code></pre>
  
  <p>Config :</p>
  
  <pre><code>package fr.myapp;
  
  import java.util.Properties;
  
  import javax.sql.DataSource;
  
  import org.hibernate.jpa.HibernatePersistenceProvider;
  import org.postgresql.Driver;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.jdbc.datasource.SimpleDriverDataSource;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.scheduling.quartz.SchedulerFactoryBean;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  
  @Configuration
  @EnableWebMvc
  @EnableTransactionManagement
  @ComponentScan("fr.myapp")
  public class WebAppConfig extends WebMvcConfigurerAdapter {
      @Autowired
      private ApplicationContext applicationContext;
  
      @Bean
      public DataSource dataSource() {
              SimpleDriverDataSource d = new SimpleDriverDataSource();
              d.setConnectionProperties(dProperties());
              d.setDriverClass(Driver.class);
              d.setUrl("jdbc:postgresql://localhost:5432/mydb");
              d.setUsername("BNF0016779");
              d.setPassword("");
              return d;
      }
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
              LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
              entityManagerFactoryBean.setDataSource(dataSource());
              entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
              entityManagerFactoryBean.setPackagesToScan("fr.myapp");
  
              entityManagerFactoryBean.setJpaProperties(hibProperties());
  
              return entityManagerFactoryBean;
      }
  
      private Properties hibProperties() {
              Properties properties = new Properties();
              properties.put("hibernate.hbm2ddl.auto", "update");
              properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
              properties.put("hibernate.show_sql", "false");
              return properties;        
      }
  
      private Properties dProperties() {
          Properties properties = new Properties();
          properties.put("spring.jpa.database", "POSTGRESQL");
          return properties;        
  }   
  
      @Bean
      public SchedulerFactoryBean configureScheduler() {
          SchedulerFactoryBean f = new SchedulerFactoryBean();
          return f;
      }
  }
  </code></pre>
  
  <p>EDIT : Service</p>
  
  <pre><code>@Service
  public class SchedulerService extends AbstractService implements ISchedulerService {
      @Autowired
      private Scheduler scheduler;
  
  //Blah...
  }
  </code></pre>
  
  <p>Another question : My War is generated inside a war project.</p>
  
  <p>Maven project arch :</p>
  
  <pre><code>-parent
  +-war (just generates war)
  +-web
  </code></pre>
  
  <p>My war project has a web dependency
  My @Configuration class is inside web project.</p>
  
  <p>Could it be the problem ?</p>
  
  <p>EDIT 2 :
  Apprently, yes !</p>