I don't know how to replace config.properties by test properties Spring / JUnit

197 Views Asked by At

The thing is that have a project that uses a configuration class to get all the config properties

   @Configuration
   @PropertySource("file:/external/path/config/config.properties")
   public class AppSettings {
        @Value("${SOME.PROPERTY}")
        public String SOME_PROPERTY;
   }

So in my test configuration class I just replace the properties using this:

@TestPropertySource("classpath:testconfig.properties")

So it's work (in my local), it replace the config by the testconfig. But when i deploy it in the certification environment it throws FileNotFoundException: /external/path/config/config.properties this config.properties is in an external path, so the deploy can not access to that path.

that testconfig.properties is inside the project so I need to read this instead of the config.properties ...but is still reading it and throwing error.

How can i replace the config.properties properly when I run test?

1

There are 1 best solutions below

1
On

Try to add dot after :

@PropertySource("file:./server/path/config/config.properties")

Also take a look at this chapter of spring documentation, it might be useful for you.