Im trying to learn Spring but Im having a little trouble using the @Autowired
annotation. When I try to run the example below im getting an nullpoint error on classA.hello();
line and im not sure why. Any hwlp would be appreciated.
ClassATest
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration(classes = {ContextConfigurationClass.class})
public class ClassATest {
@Autowired
ClassA classA;
@Test
public void test(){
classA.hello();
}
}
ClassA
package com;
import org.springframework.stereotype.Service;
@Service
public class ClassA {
public void hello(){
System.out.println("HELLO");
}
}
Context Configuration
package com;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan({"com"
})
public class ContextConfigurationClass {
}