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 6050835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:44:02+00:00 2026-05-23T07:44:02+00:00

Why is my spring bean (loginInfoDAO) which is injected properly on server start up,

  • 0

Why is my spring bean (loginInfoDAO) which is injected properly on server start up, null when I post my form to the controller? I have stepped through the setters on start up and they are injecting properly. However, I run the get method and then the post method and the values that were injected are null. Why would this happen?

Controller

    @Controller
    @RequestMapping("/login")
    public class LoginController extends BaseController{

    private LoginInfoDAO loginInfoDAO;

    public void setLoginInfoDAO(LoginInfoDAO loginInfoDAO) {
    this.loginInfoDAO = loginInfoDAO;
    }

    @RequestMapping(method=RequestMethod.GET)
    public ModelAndView getLogin(@ModelAttribute("user") final User ur) {
        ModelAndView mav = new ModelAndView("/login/login");
        return mav;
    }

        @RequestMapping(method=RequestMethod.POST)
    public ModelAndView login(@ModelAttribute("user") final User ur) {

        loginInfoDAO.login(ur);
        ModelAndView mav = new ModelAndView();
        return mav;
    }

    }

application-context.xml

        <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        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"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <bean id="myDataSource" 
    class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
      <property name="driverClassName">
        <value>com.mysql.jdbc.Driver</value>
      </property>
      <property name="url">
        <value>jdbc:mysql://localhost/databasename</value>
      </property>
      <property name="username">
        <value>databaseusername</value>
      </property>
      <property name="password">
        <value>databasepassword</value>
      </property>
      <!-- Disable the second-level cache  -->
        <!-- Echo all executed SQL to stdout -->
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="myDataSource" /> 
        <property name="annotatedClasses">
            <list>
            <value>com.projectname.model.LoginInfo</value>
            <value>com.projectname.model.User</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.show_sql">true</prop>
        </props>
        </property>
    </bean>


    <bean id="myLoginInfoDAO" class="com.projectname.dao.LoginInfoDAOImpl">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <bean name="/login" class="com.projectname.controllers.LoginController" >
        <property name="loginInfoDAO" ref="myLoginInfoDAO" />
    </bean>
    </beans>

spring-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:annotation-config />
<context:component-scan
    base-package="com.projectname" />
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <value>/WEB-INF/messages/messages</value>
    </property>
    <property name="cacheSeconds" value="60" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>
</beans>
  • 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-23T07:44:05+00:00Added an answer on May 23, 2026 at 7:44 am

    Add @Autowired for loginInfoDAO since you are using context:annotation-config.

    @Autowired
    private LoginInfoDAO loginInfoDAO;
    

    Then remove the following entries from your context xml (since they are driven with the annotation here).

       <bean id="myLoginInfoDAO" class="com.projectname.dao.LoginInfoDAOImpl">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
    
        <bean name="/login" class="com.projectname.controllers.LoginController" >
            <property name="loginInfoDAO" ref="myLoginInfoDAO" />
        </bean>
    

    This should get you going.

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

Sidebar

Related Questions

I have a resource (Spring bean) which has some of its fields injected by
I have a bean which extends other Java file. When I create a Spring
I have a Spring bean which will be used for storing user details or
Can I access spring bean that exposed using http invoker (server) from GWT application
I have two Spring proxies set up: <bean id=simpleBean class=org.springframework.aop.framework.ProxyFactoryBean> <property name=target> <ref local=simpleBeanTarget/>
I have just broken up a Spring bean configuration file into smaller external files
Assume that we have Spring bean UserController with singleton scope. All my further reasoning
I have a spring bean defined outside my control. I want to set a
I have a Spring bean, let's say: @TransactionAttribute(TransactionAttributeType.REQUIRED) public class AImpl implements A {
I have an application where I have to use Spring to load a bean

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.