Spring Injection in JUnit4 – Testcases

If you use maven then you should make sure to have the following dependencies within your pom:

Your test class should look like this:

The ContextConfiguration has to be setup with the spring configuration file, which contains all the beans that can be used for injection.

If you get initialization errors or ClassNotFoundExceptions then you should make sure to have the correct version of your dependencies installed. For JUnit it’s recommended to stick with version 4.4 since the newer versions throw a ClassNotFoundException if you combine your tests with Spring Injection.

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Spring Injection in JUnit4 – Testcases

  1. he web site was how do i say it… relevant, finally something that helped me. Many thanks

Leave a Reply

Your email address will not be published. Required fields are marked *


9 + six =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">