Announcement Announcement Module
Collapse
No announcement yet.
Why no body answer this question? NullPointerException when calling method on spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why no body answer this question? NullPointerException when calling method on spring

    Hello All,
    i am new to spring and I would appreciate any help in this?

    i have the following spring bean class

    public class HouseHoldingDBFacade implements IHouseHoldingDBDacade {
    private IUsersDAO usersDao;

    public HouseHoldingDBFacade() {

    }

    public void setUsersDao(IUsersDAO usersDao) {
    System.out.println("usersDao null? " + (usersDao == null));
    this.usersDao = usersDao;
    }



    public IUsersDAO getUsersDao() {
    return usersDao;
    }

    public UserBean isValidUserNamePassword(UserBean userBean) {
    System.out.println("usersDAO is null? " + (usersDao == null));
    return getUsersDao().isValidUserNamePassword(userBean);
    }

    }

    and in applicationContext.xml i have the following

    <bean id="derbyHHDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean" scope="singleton">
    <property name="jndiName" value="java:comp/env/jdbc/hhDb" />
    <property name="resourceRef" value="false"/>
    </bean>

    <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
    <bean id="derbyUsersDataProvider" class="com.springjsf.persistence.dao.derbyimpl.Der byUsersDAO">
    <property name="dataSource">
    <ref local="derbyHHDataSource"/>
    </property>


    </bean>

    <bean id="usersDao" class="com.springjsf.persistence.HouseHoldingDBFac ade">
    <property name="usersDao">
    <ref bean="derbyUsersDataProvider"/>
    </property>
    </bean>



    when I deploy the application I get in the first method setUsersDao System.out prints that usersDao != null and when I run the application on the isValidUserNamePassword i get that usersDao = null ? but why???????

  • #2
    Are you creating a new instance of HouseHoldingDBFacade from whereever u are calling it ? Make sure that your are using the same instance that you injected and not a new instance.

    Comment


    • #3
      yes that was the problem

      thanks man, that was the issue.

      I was everytime doing constructor injection with a new instance

      I appreciate your help!

      Comment

      Working...
      X