Below is my project structure
SomeProject
-src/main/java
-src/main/resources
-src/test/java
-src/test/resources
application-test.yml
Below are the contents of my properties file
application-test.yml
pre:
someUrl: http://someurl
Below are the contents of the configuration class
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "pre")
public class SomeConfiguration {
private String someUrl;
public String getsomeUrl() {
return someUrl;
}
public void setsomeUrl(String someUrl) {
this.someUrl = someUrl;
}
}
Below is my test class
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=SomeConfiguration.class)
@TestPropertySource(locations = {"classpath:application-test.yml"})
public class SomeServiceTest {
SomeObject someObject;
@Autowired
private SomeConfiguration someConfiguration;
@Test
public void somMethodTest() {
someObject = new SomeObject ();
someObject.setsomeUrl(someConfiguration.getsomeUrl());
}
}
The problem is I am getting null when I am trying to set someURL in someObject. I have seen similar questions on stackoverflow and accepted answers as well, but I am still getting null.