0

My Spring Boot project structure is the following:

I have my tests code in the Main class under src/test, and a test-dedicated properties file under scr/test/resources
I would like to load that file so that i can read its properties from my Main (test) java class, so i do (in the Main class):
enter image description here

But the file is not loaded, at least i assume so, because when i try to read a property in this way: @Value("${some.property.present.in.that.file}") private String prop;
then prop is always null.
I dont understand why this mechanism works in my src/main/javacode but not under test, the ApplicationContext should be there, the Main test class is annotated with @SpringBootTest which as you can see targets to itself, and the official documentation says:

enter image description here

Any advice about this?

JBoy
  • 5,398
  • 13
  • 61
  • 101

1 Answers1

0

I believe that if you move your tests to src/test/java/* the SpringBootTest will see them without any other configs.

Serg Vasylchak
  • 858
  • 4
  • 18
  • https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html#using-boot-structuring-your-code it says that it does not need a specific layout to work – JBoy Jan 03 '18 at 11:40
  • You were right, i refactored my code and magically now it works, its a bit confusing though that they say that Spring Boot will work regardless of the project structure, thx! – JBoy Jan 03 '18 at 14:17
  • @JBoy https://stackoverflow.com/questions/3004710/what-is-the-advantage-of-the-src-main-java-convention – Serg Vasylchak Jan 04 '18 at 11:18