0

I'm working on a Spring multi-module project. One of the child modules has some files under /test/resources/certs/ and a property file under /test/resources/test-ssl.properties.

───resources │ test-ssl.properties ├───certs │ test-keystore.p12

test-ssl.properties has a property that points to /certs/test-keystore.p12file.

server.ssl.trust-store=/certs/test-keystore.p12

In child modules pom.xml I'm using Maven plugin test-jar and in parent pom I've added this module as a dependency.

With this structure integration test present in parent module is able to successfully read classpath:test-ssl.properties but it fails to resolve its property value.

Spring throws FileNotFoundException: \certs\test-keystore.p12. What change we can do to make Spring read a file present in test jar?

Also tried the following patterns,

server.ssl.trust-store=classpath:/certs/test-keystore.p12

server.ssl.trust-store=classpath:certs/test-keystore.p12

server.ssl.trust-store=classpath*:/certs/test-keystore.p12

Please note that this test property doesn't try to load any certificate. It is there because property placeholder can find some value for the property during build.

Vijay Nandwana
  • 2,476
  • 4
  • 25
  • 42
  • I hope the files are under `src/test/resources`? The classpath entry should look like `classpath:/test-ssl.properties` ... – khmarbaise May 16 '18 at 08:36
  • Tried this but no go. Spring is able to read `test-ssl.properties` file successfully but the value of `server.ssl.trust-store` property. – Vijay Nandwana May 16 '18 at 08:45
  • I'm not sure if spring itself can read a certificate file cause a certificate must be done during the start of the JVM... – khmarbaise May 16 '18 at 08:46
  • This test property doesn't load any certificate, it is there so that property placeholder can find some property during integration test. This can be any file of any extension. – Vijay Nandwana May 16 '18 at 08:52

1 Answers1

0

Issue is resolved by changing integration-test phase to process-test-resources.

Credit goes to the following answer of Pascal Thivent:

The content of the test output directory (target/test-classes) is on the class path, not src/test/resources. But resources under src/test/resources are copied to the test output directory by the resources:testResources goal (which is bound by default to the process-test-resources phase).

Vijay Nandwana
  • 2,476
  • 4
  • 25
  • 42