@SpringBootTest - failed to load applicationcontext

4k views Asked by At

Test class:

@RunWith(SpringRunner.class)
@SpringBootTest
public class FileInterfaceTest {
 @Test
 public void contextLoads() {
 }

}

Application :

AppConfig:

      @Configuration
      @ImportResource({ "classpath:process-flows.xml" })
      public class AppConfig {
               }

Have Bootstraploader class.

Error:

       java.lang.IllegalStateException: Failed to load ApplicationContext
       Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [file.properties] cannot be opened because it does not exist

Resources loaction:

  src/main/resources
          ---process-flow.xml
          --- process.yml
  src/main/resources/env/cconfig
          --- file.properties
2

There are 2 answers

0
git-flo On

Your folder structure contains a typo: src/main/resources/env/cconfig has to be src/main/resources/env/config

As defined in the Spring Externalized Configuration, SpringApplication loads properties from application.properties files in the following locations and adds them to the Spring Environment:

  • A /config subdirectory of the current directory
  • The current directory
  • A classpath /config package
  • The classpath root
0
Ashish Mishra On

Apart from "cconfig" folder name (not sure if that was a typo) I also see your @ImportResource is mentioned as classpath:process-flows.xml however your resources folder has file named process-flow.xml

If that was not a typo as well, please add an 's' by renaming process-flow.xml to process-flows.xml and retry