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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:50+00:00 2026-06-13T02:26:50+00:00

Want to inject a dao that has a configured data source injected into it..

  • 0

Want to inject a dao that has a configured data source injected into it.. not a fan of annotation because it makes code ugly, i want a pure XML solution.

the test cases are in subfolders in test folder, which is at the same level as the src folder

src
   com
       name
           dao
               ProductDao
test
   com
       name
           dao
               ProductDaoTest

ProductDaoTest needs to have ProductDao injected in it. tried to do that, spring injects it ok, but the ProductDao depenedencies arenot being injected, and I am facing NPE.

thought about moving test classes into src folder, but I dont think I should have to do that. the other alternative that I am thinking of is running the test cases via the browse through controller calls (but wont be unit testing anymore), so I am stuck trying to figure out the right thing to do.

thank you!
p.s. tests are junit, tomcat, spring 3.1

  • 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-06-13T02:26:51+00:00Added an answer on June 13, 2026 at 2:26 am

    What methods in the DAO do you want to unit test? Are you not actually trying to test the DB connectivity?

    Otherwise I agree with @duffymo.

    Edit: To elaborate a bit, try to adapt the following code chunk to your test class needs:

    final ClassPathXmlApplicationContext beanFactory = 
        new ClassPathXmlApplicationContext( "applicationContext.xml" );
    AutowireCapableBeanFactory factory = beanFactory.getAutowireCapableBeanFactory();
    factory.autowireBeanProperties( this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE , true );
    ProductDao dao = context.getBean( "productDao" );
    

    and see if that doesn’t do the trick for the Dao dependency beans.

    Cheers,

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

Sidebar

Related Questions

I want to inject one additional variable into the context of a view that
Basically, I want to inject some data into ViewData/ViewBag for every single request.
I have the following json {groupOp:AND,rules:[{field:company,op:cn,data:School}]} I want to inject new properties into every
I want to inject some Json into the Html page returned by the server?
I want to inject a connection string into my repository but ideally, I want
I'm using Structure map and want to inject instance (constructed by container) into controller's
I have a function JavaScript that i want to inject in a Html, with
I want the functionality of connect.static , but I want to inject code into
I want to create a method ( set ) that injects arguments into another
I just want to inject some design patterns into my Java code, but I

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.