title: Getting Error creating bean with name
body: <p>I'm creating a Spring MVC Maven module based project so I have divided every layer into a maven module. When I try to run a basic site, code compiles fine but I get the error: </p>
  
  <pre><code>SEVERE: Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addressController' defined in file [C:\Program Files\Apache Software Foundation\Tomcat 8.0\wtpwebapps\croz-web\WEB-INF\classes\hr\croz\bspoljaric\controller\AddressController.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [hr.croz.bspoljaric.controller.AddressController] for resource metadata: could not find class that it depends on
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:525)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4851)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  Caused by: java.lang.IllegalStateException: Failed to introspect bean class    [hr.croz.bspoljaric.controller.AddressController] for resource metadata: could not find class that it depends on
  at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:344)
  at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:297)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:953)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
  ... 20 more
  Caused by: java.lang.NoClassDefFoundError: Lhr/croz/bspoljaric/service/AddressService;
  at java.lang.Class.getDeclaredFields0(Native Method)
  at java.lang.Class.privateGetDeclaredFields(Unknown Source)
  at java.lang.Class.getDeclaredFields(Unknown Source)
  at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:715)
  at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:656)
  at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.buildResourceMetadata(CommonAnnotationBeanPostProcessor.java:361)
  at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:340)
  ... 23 more
  Caused by: java.lang.ClassNotFoundException:      hr.croz.bspoljaric.service.AddressService
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
  ... 30 more
  </code></pre>
  
  <p>AddressDao.java</p>
  
  <pre><code>package hr.croz.bspoljaric.dao;
  
  import java.util.List;
  
  import hr.croz.bspoljaric.entity.Address;
  
  public interface AddressDAO {
  
  public void save(Address address);
  
  public void delete(int addressID);
  
  public Address get(int contactId);
  
  public List&lt;Address&gt; getAll();
  }
  </code></pre>
  
  <p>AddressDaoImpl.java</p>
  
  <pre><code>import java.util.List;
  
  import org.springframework.stereotype.Repository;
  
  import hr.croz.bspoljaric.dao.AddressDAO;
  import hr.croz.bspoljaric.entity.Address;
  
  @Repository
  public class AddressDAOImpl implements AddressDAO{
  
  @Override
  public void save(Address address) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void delete(int addressID) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public Address get(int contactId) {
      // TODO Auto-generated method stub
      return null;
  }
  
  @Override
  public List&lt;Address&gt; getAll() {
          List&lt;Address&gt; as = new ArrayList&lt;&gt;();
          Address a = new Address();
          a.setId(1l);
          a.setStreet("MAKSIMIRSKA");
          a.setStreetNo("2");
          a.setCity(null);
          as.add(a);
          System.out.println("TEST: " + as.get(1));
          return as;
  
  }
  
  }
  </code></pre>
  
  <p>AddressService.java</p>
  
  <pre><code>package hr.croz.bspoljaric.service;
  
  import java.util.List;
  
  import hr.croz.bspoljaric.entity.Address;
  
  public interface AddressService {
  
  public List&lt;Address&gt; getAll();
  
  }    
  </code></pre>
  
  <p>AddressServiceImpl.java</p>
  
  <pre><code>package hr.croz.bspoljaric.serviceimpl;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  import org.springframework.stereotype.Service;
  
  import hr.croz.bspoljaric.dao.AddressDAO;
  import hr.croz.bspoljaric.entity.Address;
  import hr.croz.bspoljaric.service.AddressService;
  
  @Service
  public class AddressServiceImpl implements AddressService {
  @Autowired
  AddressDAO dao;
  
  public List&lt;Address&gt; getAll() {
      return dao.getAll();
  
  }
  }
  </code></pre>
  
  <p>AddressController.java</p>
  
  <pre><code>package hr.croz.bspoljaric.controller;
  
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  
  
  import hr.croz.bspoljaric.service.AddressService;
  
  
  @Controller
  @RequestMapping("/test")
  public class AddressController {
  
  @Autowired
  AddressService ads;
  
  @RequestMapping(value = "/getAll", method = RequestMethod.GET)
  public String getAllAddresses(Model model)
  {
    model.addAttribute("addresses", ads.getAll());
    System.out.println("TEST!");
    return "addressesListDisplay";
  
   }
  
  
   }
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5"&gt;
  &lt;display-name&gt;Croz Web Application&lt;/display-name&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
              org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p></p>
  
  <p>spring-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context/
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
  &lt;context:component-scan base-package="hr.croz.bspoljaric" /&gt;
  
  
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt;
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Project view(all except web module):</p>
  
  <p><a href="https://imgur.com/a/mgBpd" rel="nofollow noreferrer">https://imgur.com/a/mgBpd</a></p>
  
  <p>Project view(web module):</p>
  
  <p><a href="https://imgur.com/a/4gtp8" rel="nofollow noreferrer">https://imgur.com/a/4gtp8</a>)</p>