3

I'm trying to set a property, as a path to a file in my resources folder, in my application.yml

But Java treats the classpath prefix as part of the string.

I've tried multiple ways of getting this path into my program (obviously not all at once).

keytab-path: classpath:/resources/krb5.keytab
keytab-path: classpath:/krb5.keytab
keytab-path: classpath:krb5.keytab
keytab-path: classpath*krb5.keytab

I can assert the property is definitely injected into my code, but it just has an issue with treating 'classpath' as a literal part of the string.

I have success in my code by injecting sql files using the classpath:sql/foo.sql with an @Sql tag.

Is there a way application.yml can interpret a classpath?

rnmalone
  • 1,020
  • 13
  • 25
  • 2
    No. Your application can, you should bind the `keytab-path` to a Spring `Resource` which will handle the loading and understands the `classpath:` prefix. – M. Deinum Jun 21 '18 at 10:49
  • @M.Deinum Your solution helped. I used a ClasspathResource and injected the path property into it. Thanks for you help. – rnmalone Jun 21 '18 at 14:50
  • 1
    Don't use a `ClasspathResource` use the `Resource` interface. Spring will take care of the conversion. That way you can also change it to a regular `file:` or `http:` prefix and it will still work. – M. Deinum Jun 21 '18 at 17:25
  • Can you share the example rnmalone – pitumalkani Jul 10 '19 at 14:07

0 Answers0