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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:41:03+00:00 2026-06-18T04:41:03+00:00

I’m having some issues running some tests with the spring junit runner. I’m using

  • 0

I’m having some issues running some tests with the spring junit runner.

I’m using Java configuration for spring, so I can’t seem to find an example that works for me.

All I want to do is write a junit test that I can use one of my dao classes in, and have it working with hibernate and everything, but for that I need it to be loaded in a real spring context.

I’ve tried writing my test class like this:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=HibernateConfig.class, loader=AnnotationConfigContextLoader.class)

public class TestNodeDao {

    @Configuration
    @ComponentScan(basePackages = "com.orclands" )
    static class Config {

        @Bean
        public NodeDao nd() {
            NodeDao nd = new NodeDao();

            return nd;
        }
    }

    @Autowired
    private NodeDao nd;

But it can’t autowire in the nodeDao. It says NoSuchBeanDefinitionException.

If I take out the trying to autowire the NodeDao, then it runs, but the whole and only point of running it as a spring test is so I can test the real spring-configured NodeDao.

I also tried it without the component scan, with the component scan but no bean declaration and some other ways, but I couldn’t get it to work.

  • 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-18T04:41:04+00:00Added an answer on June 18, 2026 at 4:41 am

    Two things…

    1. There’s no need to declare the loader.
    2. As soon as you declare explicit configuration classes, a default (i.e., your nested static configuration class) will no longer be detected.

    So try something like this:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes={HibernateConfig.class, TestNodeDao.Config.class})
    public class TestNodeDao {
    
      @Configuration
      static class Config {
    
          @Bean
          public NodeDao nd() {
            return new NodeDao();
          }
      }
    
      @Autowired
      private NodeDao nd;
    
      // ...
    }
    

    Or perhaps even cleaner:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public class TestNodeDao {
    
      @Configuration
      @Import(HibernateConfig.class)
      static class Config {
    
          @Bean
          public NodeDao nd() {
            return new NodeDao();
          }
      }
    
      @Autowired
      private NodeDao nd;
    
      // ...
    }
    

    Regards,

    Sam

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.