java调用外部java文件路径_java – 用于类路径上的外部文件的Jar中的@PropertySource...

我正在尝试在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属性中指定类路径(包含两个变量),但它总是给出相同的结果.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值