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

  • Home
  • SEARCH
  • 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 936965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:23:55+00:00 2026-05-15T21:23:55+00:00

My homecontroller has a UserService object that gets wired using spring correctly (it renders

  • 0

My homecontroller has a UserService object that gets wired using spring correctly (it renders the index page just fine using a method no UserService).

Now I setup hibernate, so inside UserService I have a UserDao object that I am trying to wire using spring.

@Service
public class UserServiceImpl implements UserService{

    UserDao userDao;

    public String sayHello() {

        return "hello from user service impl part 2";

    }

    public String getTestUser() {





        return userDao.getById(1L).getUsername();

    }

}

So my HomeController was calling the ‘sayHello’ method and it was working fine like I said.

@Controller
public class HomeController {

    @Autowired
    private UserService userService;




    @RequestMapping("/")
    public ModelAndView Index() {



        ModelAndView mav = new ModelAndView();

        mav.setViewName("index");
        mav.addObject("message", userService.sayHello());

        mav.addObject("username", userService.getTestUser());
        //userService.getTestUser();

        return mav;
    }

The call to userService.getTestUser() fails, as the UserDao is null.

My app-config.xml is:

<!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!--<property name="packagesToScan" value="com.blah.core.db.hibernate"/>  -->
        <property name="configLocation" value="/WEB-INF/classes/hibernate.cfg.xml"/> 
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.MySQLDialect
                hibernate.connection.url=jdbc:mysql://localhost/blah
                hibernate.connection.username=dbuser
                hibernate.connection.password=123
                hibernate.query.substitutions=true 'Y', false 'N'
                hibernate.cache.use_query_cache=true
                hibernate.cache.use_second_level_cache=true
                hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
                hibernate.jdbc.batch_size=0
            </value>
        </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->


     <bean id="userDao" class="com.blah.core.db.hibernate.UserDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

Why is my UserDao null? I must be doing something wrong with the wiring?

Also, if I uncomment out the name=packagesToScan line, do I really need to define a bean for each Dao like I did with UserDao? Will the sessionFactory get wired somehow?

  • 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-15T21:23:55+00:00Added an answer on May 15, 2026 at 9:23 pm

    Add @AutoWired annotation to userDao.

    @Service
    public class UserServiceImpl implements UserService{
    
        @AutoWired
        UserDao userDao;
    
        ...
    }
    

    And make sure you have set up <context:component-scan/> to scan the packages that your @Services and @Controllers are in.

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

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I finally found some time to do some experiments in… May 16, 2026 at 11:11 am
  • Editorial Team
    Editorial Team added an answer ASP.NET and classic ASP are two completely different technologies. Classic… May 16, 2026 at 11:11 am
  • Editorial Team
    Editorial Team added an answer Check to make sure that dic is released. You should… May 16, 2026 at 11:11 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

How can you instantiate a Controller that has an int argument? Using Ninject.. My
i have some header tabs on a basic index.aspx page that uses a masterpage.
My app-config.xml has a definition for my UserDao bean: <bean id=userDao class=com.blah.core.db.hibernate.UserDaoImpl> <property name=sessionFactory
I am using ASP.NET MVC 1.1 with Windows authentication. I trying to only authorize
I know this has been asked before but I can't find it so... Say
Has anyone been able to get the Areas in ASP.NET MVC 2 to work?
I have started an MVC project and it has created the AccountController Class for
I have an ActionResult in my HomeController defined to return JSON. The JSON is
Anyone know if it's possible to move the HomeController and Home related views into
I have wrong URL in my ajax calls. $.ajax({ type: POST, url: Home/GetDetails, ......

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.