title: Spring-data cassandra tomcat webapp - Could not autowire CassandraOperations
body: <p>I get the following error when starting the webapp. I tried to read up the Spring Data docs, but they are incomplete. Any help is appreciated. </p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dao.UserDao controller.LoginController.userDao; nested exception is     org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dao.UserDao] 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:555)
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
  ... 56 more
  </code></pre>
  
  <p>Below are the details of my project:</p>
  
  <pre>
  **Structure**
  src
   main
     java
      bean
          Person.java
      configuration
          ApplicationConfiguration
          CassandraConfiguration    
      controller
          LoginController
      dao
          UserDao
  </pre>
  
  <p>
              contextClass
              org.springframework.web.context.support.AnnotationConfigWebApplicationContext
          </p>
  
  <pre><code>    &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;configuration.ApplicationConfiguration&lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;applicationContext&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextClass&lt;/param-name&gt;
              &lt;param-value&gt;
                  org.springframework.web.context.support.AnnotationConfigWebApplicationContext
              &lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;configuration&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;applicationContext&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  
      &lt;context-param&gt;
          &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;WEB-INF/log4j.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  </code></pre>
  
  <p>ApplicationConfiguration.java   </p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = "controller, dao")
  @EnableWebMvc
  
  public class ApplicationConfiguration {
  
  private static final Logger LOG = LoggerFactory.getLogger(ApplicationConfiguration.class);
  
      @Bean
      public User user() {
          return new User();
      }
      @Autowired
      private CassandraOperations cassandraOps;
  
      @Bean
      TilesViewResolver viewResolver(){
          TilesViewResolver viewResolver = new TilesViewResolver();
          return viewResolver;
      }
  
      @Bean
      TilesConfigurer tilesConfigurer(){
          TilesConfigurer tilesConfigurer = new TilesConfigurer();
          tilesConfigurer.setDefinitions("WEB-INF/tiles-definitions.xml");
          tilesConfigurer.setPreparerFactoryClass(org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory
              .class);
          return tilesConfigurer;
      }
  }
  </code></pre>
  
  <p>CassandraConfiguration.java</p>
  
  <pre><code>@Configuration
  @PropertySource(value = { "classpath:cassandra.properties" })
  @EnableCassandraRepositories(basePackages = { "dao" })
  public class CassandraConfiguration {
  
      private static final Logger LOG = LoggerFactory.getLogger(CassandraConfiguration.class);
      @Autowired
      private Environment env;
  
      @Bean
      public CassandraClusterFactoryBean cluster() {
  
          CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
          cluster.setContactPoints(env.getProperty("cassandra.contactpoints"));
          cluster.setPort(Integer.parseInt(env.getProperty("cassandra.port")));
  
          return cluster;
      }
  
      @Bean
      public CassandraMappingContext mappingContext() {
          return new BasicCassandraMappingContext();
      }
  
      @Bean
      public CassandraConverter converter() {
          return new MappingCassandraConverter(mappingContext());
      }
  
      @Bean
      public CassandraSessionFactoryBean session() throws Exception {
  
          CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
          session.setCluster(cluster().getObject());
          session.setKeyspaceName(env.getProperty("cassandra.keyspace"));
          session.setConverter(converter());
          session.setSchemaAction(SchemaAction.NONE);
  
          return session;
      }
  
      public CassandraOperations cassandraTemplate() throws Exception {
          return new CassandraTemplate(session().getObject());
      }
  </code></pre>
  
  <p>LoginController</p>
  
  <pre><code>@Controller
  public class LoginController {
      private final static Logger logger = Logger.getLogger(LoginController.class);
  
      @Autowired
      private UserDao userDao;
  
      @RequestMapping(value = Constants.WEBAPP_CONTEXT + "/login.do", method = RequestMethod.GET)
      public ModelAndView login() {
          userDao.addUser();
          return new ModelAndView("login-tile");
      }
     }
  </code></pre>
  
  <p>UserDao
      @Repository("userDao")
      public class UserDao {</p>
  
  <pre><code>    public static final String TIME_BUCKET = "2014-01-01";
  
      @Autowired
      private CassandraOperations cassandraOps;
  
      public void addUser() {
          cassandraOps.insert(new Person("1234567890", "David", 40));
      }
  }
  </code></pre>