title: Getting Error of Error creating bean with name 'bookMasterController': Injection of autowired dependencies failed;
body: <p>I am using Spring 3.2 and Hibernate but i am getting eror of that its not allowing to create bean of SessionFacotry from the XML file i dont know why this error is coming. i have search alot but not finding exceat ans please help for the same.</p>
  
  <p>Here my file is 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:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"&gt;
  
      &lt;!-- For context suppport of the Controller --&gt;
  
      &lt;context:annotation-config&gt;&lt;/context:annotation-config&gt;
      &lt;context:component-scan base-package="com.book.controller"&gt;&lt;/context:component-scan&gt;
  
  
      &lt;!-- For enable the MVC Support --&gt;
      &lt;!-- &lt;mvc:annotation-driven /&gt;
      &lt;mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"&gt;&lt;/mvc:resources&gt;
   --&gt;
      &lt;!-- Enabling the suppot the UI user side --&gt;
      &lt;bean id="jspViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/view/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
  
  
  
      &lt;!-- For messages for the Labels --&gt;
  
      &lt;bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="classpath:messages" /&gt;
          &lt;property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/bean&gt;
  
  
      &lt;!-- For the Properties of JDBC --&gt;
      &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/jdbc.properties" /&gt;
  
      &lt;!--Database Properties --&gt;
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
          p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /&gt;
  
      &lt;!-- Session facotry configration --&gt;
      &lt;bean id="hibernate4AnnotatedSessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;!-- &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt; --&gt;
          &lt;property name="packagesToScan" value="com.book.bookentity" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- implementation bean config. --&gt;
  
      &lt;bean id="autherMasterServiceInterfacecontroller" class="com.book.service.AutherMasterServiceInterfaceImpl"&gt;&lt;/bean&gt;
      &lt;bean id="bookMasterServiceInterfacecontroller" class="com.book.service.BookMasterServiceInterfaceImpl"&gt;&lt;/bean&gt;
      &lt;bean id="emailMasterInterfacecontroller" class="com.book.service.EmailMasterInterfaceImpl"&gt;&lt;/bean&gt;
      &lt;bean id="languageMasterinterfacecontroller" class="com.book.service.LanguageMasterinterfaceimpl"&gt;&lt;/bean&gt;
  
  
  
  
      &lt;bean id="bookMasterInterface" class="com.book.bookDao.BookMasterInterfaceImpl"&gt;
          &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean id="emailMasterInterface" class="com.book.bookDao.EmailMasterInterfaceImpl"&gt;
          &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean id="languageMasterInterface" class="com.book.bookDao.LanguageMasterInterfaceImpl"&gt;
          &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean id="autherMasterInterface" class="com.book.bookDao.AutherMasterInterfaceImpl"&gt;
          &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
      &lt;/bean&gt;
  
  
  
      &lt;!-- Enabling transction managar --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  
      &lt;!-- Config Tranaction Managar --&gt;
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /&gt;
      &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>bean class1</p>
  
  <pre><code>@Entity
  @Table(name = "tbl_bookmaster", uniqueConstraints = { @UniqueConstraint(columnNames = "bid") })
  public class BookMasterTable {
  
      @Id
      @GeneratedValue
      @Column(name = "bid")
      private int bookid;
  
      @Column(name = "bookname")
      private String bookname;
  
      @Column(name = "booktype")
      private String booktype;
  
      @Column(name = "bookprice")
      private String bookprice;
  
      @Column(name = "bestsaler")
      private int bestsaller;
  
      @ManyToOne
      @JoinColumn(name = "lid")
      private LanguageMasterTable languageMasterTable;
  
      @ManyToOne
      @JoinColumn(name = "auid")
      private AutherMasterTable autherMasterTable;
  
      @ManyToOne
      @JoinColumn(name = "mailid")
      private EmailMasterTable emailMasterTable;
  
  
      // getter and setter
  
      }
  </code></pre>
  
  <p>bean2 </p>
  
  <pre><code>@Entity
  @Table(name = "tbl_contactmaster")
  public class EmailMasterTable implements Serializable{
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue
      @OneToMany
      @JoinColumn(name = "authercontactmail")
      private Set&lt;BookMasterTable&gt; bookMasterTables;
  
      @Column(name = "emailcontact")
      private String emailcontact;
  
  }
  </code></pre>
  
  <p>bean 3</p>
  
  <pre><code>@Entity
  @Table(name = "tbl_authermaster")
  public class AutherMasterTable {
  
      @Id
      @GeneratedValue
      @OneToMany
      @JoinColumn(name = "auid")
      private Set&lt;BookMasterTable&gt; bookMasterTables;
  
      @Column(name = "authername")
      private String authername;
     // getter and setter
  }
  </code></pre>
  
  <p>bean 4</p>
  
  <pre><code>public class LanguageMasterTable {
  
      @Id
      @GeneratedValue
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @JoinColumn(name = "language")
      private Set&lt;BookMasterTable&gt; bookMasterTables;
  
      @Column(name = "languagename")
      private String languagename;
  
      // getter and setter
  }
  </code></pre>
  
  <p>controller bean</p>
  
  <pre><code>@Controller
  public class BookMasterController {
  
      @Autowired
      private BookMasterServiceInterface bookMasterServiceInterfacecontroller;
  
  
      @RequestMapping(value="/addbook",method= RequestMethod.POST)
      public String addAuther(@ModelAttribute("book") BookMasterTable bookMasterTable){
  
          bookMasterServiceInterfacecontroller.addBook(bookMasterTable);
          return "bookadded";
      }
  }
  </code></pre>
  
  <p>like that having all controller for each bean class</p>
  
  <p>service interface</p>
  
  <pre><code>public interface BookMasterServiceInterface {
      public void addBook(BookMasterTable bookMasterTable);
  }
  </code></pre>
  
  <p>service calss</p>
  
  <pre><code>@Service
  public class BookMasterServiceInterfaceImpl implements BookMasterServiceInterface{
      @Autowired
      private BookMasterInterface bookMasterInterface;
  
      @Override
      @Transactional
      public void addBook(BookMasterTable bookMasterTable) {
          // TODO Auto-generated method stub
          bookMasterInterface.addBooks(bookMasterTable);
  
      }
  }
  </code></pre>
  
  <p>like that having service for all bean</p>
  
  <p>Repository class interface</p>
  
  <pre><code>public interface BookMasterInterface {
      public void addBooks(BookMasterTable bookMasterTable);
  }
  </code></pre>
  
  <p>repository class implementation having for each bean </p>
  
  <pre><code>@Repository
  public class BookMasterInterfaceImpl implements BookMasterInterface {
      @Autowired
      private SessionFactory sessionFactory;
  
      @Override
      public void addBooks(BookMasterTable bookMasterTable) {
          // TODO Auto-generated method stub
  
          try {
              sessionFactory.getCurrentSession().save(bookMasterTable);
          } catch (Exception e) {
              // TODO: handle exception
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>and what error i am getting is.</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.book.service.BookMasterServiceInterface com.book.controller.BookMasterController.bookMasterServiceInterfacecontroller; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookMasterServiceInterfacecontroller': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.book.bookDao.BookMasterInterface com.book.service.BookMasterServiceInterfaceImpl.bookMasterInterface; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookMasterInterface': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.book.bookDao.BookMasterInterfaceImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/BookServletmvc-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
      ... 20 more
  </code></pre>
  
  <p>main this is that is not allowing to create because its getting null pointer but i dont know where here.</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/BookServletmvc-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
      ... 48 more
  Caused by: java.lang.NullPointerException
      at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:538)
      at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:126)
      at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
      at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1514)
      at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1437)
      at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
      at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
      at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
      at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
      ... 58 more
  </code></pre>
  
  <p>i will be happy if u can help :)</p>
  
  <p>i have four entities. first one is</p>
  
  <pre><code>@Entity
  @Table(name = "tbl_bookmaster", uniqueConstraints = { @UniqueConstraint(columnNames = "bid") })
  public class BookMasterTable {
  
      @Id
      @GeneratedValue
      @Column(name = "bid")
      private int bookid;
  
      @Column(name = "bookname")
      private String bookname;
  
      @Column(name = "booktype")
      private String booktype;
  
      @Column(name = "bookprice")
      private String bookprice;
  
      @Column(name = "bestsaler")
      private int bestsaller;
  
      @ManyToOne
      @JoinColumn(name = "lid")
      private LanguageMasterTable languageMasterTable;
  
      @ManyToOne
      @JoinColumn(name = "auid")
      private AutherMasterTable autherMasterTable;
  
      @ManyToOne
      @JoinColumn(name = "mailid")
      private EmailMasterTable emailMasterTable;
  
      public int getBookid() {
          return bookid;
      }
  
      public void setBookid(int bookid) {
          this.bookid = bookid;
      }
  
      public String getBookname() {
          return bookname;
      }
  
      public void setBookname(String bookname) {
          this.bookname = bookname;
      }
  
      public String getBooktype() {
          return booktype;
      }
  
      public void setBooktype(String booktype) {
          this.booktype = booktype;
      }
  
      public String getBookprice() {
          return bookprice;
      }
  
      public void setBookprice(String bookprice) {
          this.bookprice = bookprice;
      }
  
      public int getBestsaller() {
          return bestsaller;
      }
  
      public void setBestsaller(int bestsaller) {
          this.bestsaller = bestsaller;
      }
  
      public LanguageMasterTable getLanguageMasterTable() {
          return languageMasterTable;
      }
  
      public void setLanguageMasterTable(LanguageMasterTable languageMasterTable) {
          this.languageMasterTable = languageMasterTable;
      }
  
      public AutherMasterTable getAutherMasterTable() {
          return autherMasterTable;
      }
  
      public void setAutherMasterTable(AutherMasterTable autherMasterTable) {
          this.autherMasterTable = autherMasterTable;
      }
  
      public EmailMasterTable getEmailMasterTable() {
          return emailMasterTable;
      }
  
      public void setEmailMasterTable(EmailMasterTable emailMasterTable) {
          this.emailMasterTable = emailMasterTable;
      }
  
  }
  </code></pre>