有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在spring上下文中通过类路径引用文件

我正在尝试设置org.springframework.beans.factory.config.PropertyPlaceholderConfigurerSpringbean,我有jdbc。在src/main/config中的属性。。当我把这个文件放入src/main/resources并将classpath:放入值时,我的应用程序成功部署

当jdbc出现时,这种方法就起作用了。属性位于src/main/resources

 <property name="location" value="classpath:jdbc.properties" />

然而,我需要在src/main/config内放置任何配置,如何以正确的方式将弹簧指向该位置


共 (2) 个答案

  1. # 1 楼答案

    这是类路径问题,不是Spring问题。将src/main/config添加到类路径中,它就会工作。在Eclipse中,这意味着将其添加到项目构建路径中->;来源

  2. # 2 楼答案

    正确的答案是matt b

    "What I am referring to is the fact that when you package the application, the config files are not packaged in a folder named src/main/config in the packaged file (jar/war/etc.). Therefore your answer only works when you run the application within the source code, or when src/main/config is in the classpath (which it is not by default). The correct prefix is to use classpath: or another location."

    在这个问题上:

    Trying to setup externalizing properties in spring