I am writing Junit for my Spring 4 application where I am using test.properties file from src/test/resources directory for test properties as below
<context:property-placeholder location="classpath:test.properties" />
Below is my Junit test
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:spring-servlet.xml")
public class MyHandlerTest {
}
In my application I have classes which has @Service annotation as below
@Service
public class MyHandler {
@Inject
Environment env;
//rest of the code
}
When in my handler I am trying to get property as
env.getProperty("someProperty");
I am getting null value here, so my problem is how I can access properties from all my classes?
Update
I got confuse, actually null pointer is because of it is not Autowring the interface, I have
@Service
public class MyHandler {
@Inject
Environment env;
@Autowired
Util util;
//rest of the code
}
Where I am getting null for util, can somebody let me know how Autowired interface works in Junit, from spring-servlet.xml file I am scanning all packages but still Autowire is null.