Skip to content
Advertisement

Spring Test cannot get Spring Configuration Beans

JavaScript

I also tried putting EnvironmentServiceTestConfiguration as a non-inner non-static class, but didn’t help.

Here is what I tried in a separate class:

JavaScript

didn’t work either

The test class is located in test/java/com.bhavya.test package. I am trying to run this particular test test1

This is my first test of such kind. I have never before used AnnotationConfigContextLoader.class, enlighten me.

Stacktrace :

java.lang.NullPointerException

at Line number where I have statement :

JavaScript

Advertisement

Answer

Try using @RunWith(SpringJUnit4ClassRunner.class)

Here is an example explaining how can be done https://www.mkyong.com/unittest/junit-spring-integration-example/

Here is a code sample that works for the sample in the question:

package com.example.demo.test;

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement