我正在尝试在Jar中使用
Spring框架的@PropertySource注释来从jar外部加载属性文件,但它没有找到该文件.
我需要将属性文件放在Jar的外部,以便进行编辑.我不知道文件的确切位置,我想我可以把它放在类路径的任何地方.
我在我的Config类上使用以下注释.
@PropertySource('classpath:stc.properties')
并将stc.properties放在与创建的Jar文件相同的目录中.我尝试在java命令中显式指定类路径,但它仍然无法找到该文件:
java -cp . -jar stc.jar
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.example.stc.Config; nested exception is java.io.FileNotFoundException: class path resource [stc.properties] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:162)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:299)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
[...]
等等.
我也尝试使用./作为类路径,并尝试在jar的清单的Class-Path属性中指定类路径(包含两个变量),但它总是给出相同的结果.