Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3394976
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:14:05+00:00 2026-05-18T04:14:05+00:00

I am new to Spring and Hibernate. I tried to create a simple application

  • 0

I am new to Spring and Hibernate. I tried to create a simple application using JSF, Spring and Hibernate. When I am try to run the application through Eclipse, I am getting this error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AddressBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.address.AddressBean]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)


Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.address.AddressBean]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
... 31 more
Caused by: java.lang.NullPointerException
at com.util.FacesUtil.getServletContext(FacesUtil.java:33)
at com.address.AddressBean.<init>(AddressBean.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
... 33 more

Relevant part of the view

<h:outputText value="Address:"/>
            <h:inputText value="#{addressBean.address.address}"/><br />
            <h:outputText value="City:"/>
            <h:inputText value="#{addressBean.address.city}"/><br />
            <h:outputText value="Contact Id:"/>
            <h:inputText value="#{addressBean.address.contactId}"/><br />
            <h:outputText value="Country:"/>
            <h:inputText value="#{addressBean.address.country}"/><br /><br />
            <h:commandButton value="Submit" action="#{addressBean.addAddress}" />

This is my AddressBean

public AddressBean()
{
    ServletContext servletContext = FacesUtil.getServletContext();
    this.context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
}
public String addAddress()
{
    dao = (AddressDAOImpl)context.getBean("AddressDAOImpl");
    dao.saveAddress(address);
    return "";
}

and this is my applicationcontext.xml code

<!-- Hibernate SessionFactory Definition -->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingResources">
        <list>
            <value>
                com/address/Address.hbm.xml
            </value>                
        </list>
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.MySQLDialect
            </prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">
                true
            </prop>
            <prop key="hibernate.cache.provider_class">
                org.hibernate.cache.HashtableCacheProvider
            </prop>
            <prop key="hibernate.connection.useUnicode">true</prop>
            <prop key="hibernate.connection.characterEncoding">UTF-8</prop>
        </props>
    </property>

    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
</bean>

<!-- Spring Data Access Exception Translator Definition -->
<bean id="jdbcExceptionTranslator"
    class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
</bean>

<!-- Hibernate Template Definition -->
<bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
    <property name="jdbcExceptionTranslator">
        <ref bean="jdbcExceptionTranslator" />
    </property>
</bean> 


<bean id="AddressBean"
    class="com.address.AddressBean">
    <property name="hibernateTemplate">
        <ref bean="hibernateTemplate" />
    </property>
    <property name="addressDAO">
        <ref bean="addressDAO" />
    </property>
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>

<!-- ========================= Start of SERVICE DEFINITIONS =========================
-->

<!-- Hibernate Transaction Manager Definition -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>

Please correct my mistake. Please update me if miss any detail.

Update
@chkal I tried as you said and followed this tutorial and modified the applicationcontext.xml file as below

<bean id="dao" class="com.address.AddressDAO">                      
</bean>
<bean id="addressBean"
    class="com.address.AddressBean">
    <property name="dao">
        <ref local="dao" />
    </property>                 
</bean>

Now the error comes as follows

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.address.AddressDAO]: Specified class is an interface
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFact....

If I am completely wrong, please suggest me a good tutorial for a beginner like me

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:14:05+00:00Added an answer on May 18, 2026 at 4:14 am

    It seems like you are trying to use regular JSF managed beans and some workaround to get references to beans managed by Spring (like the DAO).

    This is not the recommended way of handling this. You should really take a look at the JSF integration of Spring. If you are using this way you won’t need to use JSF managed beans at all. You will just declare your JSF beans as regular Spring beans and will be able to access them by using EL expressions just like regular JSF managed beans. Then you can also use @Autowired to inject other Spring beans (like your DAO) into your JSF bean.

    Add this to your faces-config.xml:

    <faces-config>
      <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
      </application>
    </faces-config> 
    

    Then change your AddressBean to something like this:

    @Component("addressBean")
    @Scope("request")
    public class AddressBean {
    
      @Autowired
      private AddressDAO dao;
    
      public String addAddress()
      {
          dao.saveAddress(address);
          return "";
      }
    
    }
    

    You won’t even have to change your view, as this example will add the AddressBean to the EL context under the name addressBean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Web application using spring and hibernate and struts (it runs on
I tried creating a small example using Spring, rest, Hibernate. In order to have
I m very new in spring batch project.I m trying to create a project
I'm new to spring controllers using annotated controllers. Here is my configuration Bean definition
I am new to spring and I am currently using ClassPathXmlApplicationContext to getBean inside
I am using Hibernate 3.5.2 and Spring Core 3.0.1 in a Java J2EE Web
I'm having problems using Hibernate and SQL Server 2008. When I try to save
I'm using hibernate, Spring and Velocity in Java. I'm extending the SimpleFormController and using
I am working on a domain model using Hibernate for a new project. I
Our application is based on spring, JPA, Hibernate (3.5.1), postgresql 8.4 We will deliver

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.