title: Error creating bean with name 'managedBeanClass': Unsatisfied dependency expressed through field 'person':
body: <p>I'm new comer for the spring-mvc. I tried to find good tutorial for develop test project using spring-mvc, hibernate, mysql and jsf. Finally I created sample project.</p>
  
  <p><a href="https://i.stack.imgur.com/wBKB2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wBKB2.jpg" alt="Here"></a> is capture of my project</p>
  
  <p><strong>My first question is,</strong></p>
  
  <blockquote>
    <p>Is this spring-mvc structure</p>
  </blockquote>
  
  <p>But unfortunately it's show above error.</p>
  
  <p><strong>applicationContext.xml</strong> </p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"&gt;
  
          &lt;context:annotation-config /&gt;
  
          &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
              &lt;beans:property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
              &lt;beans:property name="url"
                  value="jdbc:mysql://localhost:3306/vehicles" /&gt;
              &lt;beans:property name="username" value="root" /&gt;
              &lt;beans:property name="password" value="root" /&gt;
          &lt;/beans:bean&gt; 
  
          &lt;!-- Hibernate 4 SessionFactory Bean definition --&gt;
          &lt;beans:bean id="hibernate4AnnotatedSessionFactory"
              class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
              &lt;beans:property name="dataSource" ref="dataSource" /&gt;
              &lt;beans:property name="annotatedClasses"&gt;
                  &lt;beans:list&gt;
                      &lt;beans:value&gt;com.journaldev.springhibernate.model.Person&lt;/beans:value&gt;
                  &lt;/beans:list&gt;
              &lt;/beans:property&gt;
              &lt;beans:property name="hibernateProperties"&gt;
                  &lt;beans:props&gt;
                      &lt;beans:prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect
                      &lt;/beans:prop&gt;
                      &lt;beans:prop key="hibernate.show_sql"&gt;true&lt;/beans:prop&gt;
                  &lt;/beans:props&gt;
              &lt;/beans:property&gt;
          &lt;/beans:bean&gt;
  
  
  
          &lt;context:component-scan base-package="com.journaldev" /&gt;
  
          &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
          &lt;beans:bean id="transactionManager"
              class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
              &lt;beans:property name="sessionFactory"
                  ref="hibernate4AnnotatedSessionFactory" /&gt;
          &lt;/beans:bean&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p><strong>faces-config.xml</strong></p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;faces-config version="2.2"
                xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"&gt;
  
      &lt;application&gt;
          &lt;el-resolver&gt;
              org.springframework.web.jsf.el.SpringBeanFacesELResolver
          &lt;/el-resolver&gt;
      &lt;/application&gt;
  
  &lt;/faces-config&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
  http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;
  
    &lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.web.context.ContextLoaderListener
      &lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.web.context.request.RequestContextListener
      &lt;/listener-class&gt;
    &lt;/listener&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&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;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/test/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>Person class</strong></p>
  
  <pre><code>@Entity
  @Table(name="PERSON")
  public class Person {
  @Id
  @Column(name="id")
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private int id;
  
  @Column(name="name")
  private String name;
  
  @Column(name="country")
  private String country;
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getCountry() {
      return country;
  }
  
  public void setCountry(String country) {
      this.country = country;
  }
  
  @Override
  public String toString(){
      return "id="+id+", name="+name+", country="+country;
  }
  }
  </code></pre>
  
  <p><strong>PersonDAOImpl class</strong></p>
  
  <pre><code>@Repository
  public class PersonDAOImpl implements PersonDAO{
  
  private static final Logger logger = 
  LoggerFactory.getLogger(PersonDAOImpl.class);
  
  private SessionFactory sessionFactory;
  
  public void setSessionFactory(SessionFactory sf){
      this.sessionFactory = sf;
  }
  
  @Override
  public void addPerson(Person p) {
      Session session = this.sessionFactory.getCurrentSession();
      session.persist(p);
      logger.info("Person saved successfully, Person Details="+p);
  }
  
  }
  </code></pre>
  
  <p><strong>PersonServiceImpl class</strong></p>
  
  <pre><code>@Service
  public class PersonServiceImpl implements PersonService {
  
  @Autowired
  private PersonDAO personDAO;
  
  @Override
  @Transactional
  public void addPerson(Person p) {
      personDAO.addPerson(p);
  }
  }
  </code></pre>
  
  <p><strong>ManagedBeanClass class</strong></p>
  
  <pre><code>@ManagedBean("managedBeanClass")
  @ViewScoped
  public class ManagedBeanClass implements Serializable{
  
  @Autowired
  private Person person;
  
  @Autowired
  private PersonService personServiceImpl;
  
  public void addPersion(){
      personServiceImpl.addPerson(person);
  
  }
  
  public Person getPerson() {
      return person;
  }
  
  public void setPerson(Person person) {
      this.person = person;
  }
  
  }
  </code></pre>
  
  <p><strong>Error is,</strong></p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'managedBeanClass': Unsatisfied dependency expressed through field 'person': No qualifying bean of type [com.journaldev.springhibernate.model.Person] found for dependency [com.journaldev.springhibernate.model.Person]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.journaldev.springhibernate.model.Person] found for dependency [com.journaldev.springhibernate.model.Person]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  Aug 28, 2017 5:04:46 PM org.springframework.web.context.ContextLoader initWebApplicationContext
  SEVERE: Context initialization failed
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'managedBeanClass': Unsatisfied dependency expressed through field 'person': No qualifying bean of type [com.journaldev.springhibernate.model.Person] found for dependency [com.journaldev.springhibernate.model.Person]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.journaldev.springhibernate.model.Person] found for dependency [com.journaldev.springhibernate.model.Person]: 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:569)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      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:776)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4853)
      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(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.journaldev.springhibernate.model.Person] found for dependency [com.journaldev.springhibernate.model.Person]: 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.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1406)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1057)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
      ... 24 more
  </code></pre>
  
  <p>Please give me a answer. I tried this since long time. I can build project using spring. But I need to build with <code>spring-mvc</code> with  <strong>@Autowired</strong> annotation.</p>