I am have a normal Spring Application (Not a Spring Boot )
When I am running the Integration Test using Spock , the dependent dataUtils Autowired is null
These are my classes
RunWith(SpringRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = AppConfig.class)
class DataProcessorTest extends Specification {
def 'call '() {
given:
DataProcesser dataProcessor = new DataProcesser()
when:
dataProcessor.importData()
then:
assert 2 == 2
}
}
Can anybody please let me know what could be the issue ??
You create
DataProcessorobject as normal object usingnew, not as bean.@Autowiredis a method of automatically injecting a bin into an object created as bin.If you use
@AutowiredanddataUtilsinDataProcessoris not null, you must createDataProcessorfor bean, like below.Here is a link for your reference.
https://www.baeldung.com/spring-autowire