英文:
@PropertySource with the right classpath
问题
I have a microservice (name = "microservice-porting.jar") inside a directory "/opt/microservice-porting/". Inside the directory, I have a config folder with an application properties file application.yml.
The structure is:
microservice-porting/
    microservice-porting.jar
    config/
        application.yaml
In my code:
@PropertySource(value = "classpath:/microservice-porting/config/application.yml", factory = MultipleYamlPropertySourceFactory.class)
but I always get an exception:
Caused by: java.io.FileNotFoundException: class path resource
[microservice-porting/config/application.yml] cannot be opened because
it does not exist
All these files and directories are on a remote server where I deploy the jar files.
What is the right classpath for my case?
英文:
I have a microservice (name = "microservice-porting.jar") inside a directory "/opt/microservice-porting/". Inside the directory, I have a  config folder
with an application properties file application.yml.
The structure is:
microservice-porting/
    microservice-porting.jar
    config/
        application.yaml
In my code:
@PropertySource(value = "classpath:/microservice-porting/config/application.yml", factory = MultipleYamlPropertySourceFactory.class)
but i always get exception:
> Caused by: java.io.FileNotFoundException: class path resource
> [microservice-porting/config/application.yml] cannot be opened because
> it does not exist
All these files and directories are at a remote server where i deploy the jar files.
What is the right classpath for may case?
答案1
得分: 1
To access the application.yml file located in the config folder, specify the classpath as follows:
@PropertySource(value = "classpath:/config/application.yml", factory = MultipleYamlPropertySourceFactory.class)
Make sure the config folder is located in the same directory as your JAR file.
英文:
To access the application.yml file located in the config folder, specify the classpath as follows:
@PropertySource(value = "classpath:/config/application.yml", factory = MultipleYamlPropertySourceFactory.class)
Make sure the config folder is located in the same directory as your JAR file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论