简体   繁体   English

找不到Spring“ classpath:”位置

[英]Not able to find Spring “classpath:” location

I have a Spring Project where I am using bean configuration file beans.xml .Inside the bean Configuration file, i have defined some properties for a PlaceHolder which refers to classPath...While the application is running, the properties are getting loaded from /unknownPath/Dev/Loc1/System.properties 我有一个Spring Project,正在使用bean配置文件beans.xml在bean配置文件中,我为PlaceHolder定义了一些属性,该属性引用了classPath ...在应用程序运行时,这些属性从/unknownPath/Dev/Loc1/System.properties加载/unknownPath/Dev/Loc1/System.properties

Where 哪里

${BUS_ENV}=Dev
${LOCATION1}=Loc1

<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
            <value>classpath:${BUS_ENV}/lbsprocessor.properties</value>
        </list>
    </property>
    <!-- Force system properties to override any deployed runtime properties -->
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="ignoreUnresolvablePlaceholders" value="true" />

</bean>
  1. I didn't specify classpath while running my project in IDE 我在IDE中运行项目时未指定类路径
  2. I don't have those files in my resource folder 我的资源文件夹中没有这些文件
  3. There are around 65 such files exists(for various reasons) as Dev/Loc1/System.properties 由于各种原因,存在大约65个此类文件(由于各种原因),例如Dev/Loc1/System.properties
  4. I am not able to find from which location the properties are getting referred. 我找不到从哪个位置引用属性。 Even after debugging, I couldn't find out what classpath refers to. 即使在调试之后,我也找不到类路径是指什么。 Please help me with figuring out 请帮我弄清楚

If you are using eclipse IDE right click on your project select properties then select Java Build Path. 如果使用的是eclipse IDE,请在项目上单击鼠标右键,选择“属性”,然后选择“ Java构建路径”。 On first tab Source there is one input named Default Output folder that value is your classpath. 在第一个选项卡Source上,有一个名为Default Output文件夹的输入,该值是您的类路径。 Check all your properties files are there in that path. 检查所有属性文件是否在该路径中。

Referring to your point 2 problems might be in these line 提到您的point 2问题可能在这些行中

<value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>classpath:${BUS_ENV}/lbsprocessor.properties</value>

You are using classpath for file location which means these properties file have to be in the .war file at /Dev/Loc1/System.properties 您正在使用classpath作为文件位置,这意味着这些属性文件必须位于/Dev/Loc1/System.properties的.war文件中

If properties files are outside of project may be at system level you can access them like this 如果属性文件不在项目中,则可能在系统级别,您可以像这样访问它们

<value>file:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>file:${BUS_ENV}/lbsprocessor.properties</value>

eg: 例如:

<value>file:/home/testuser/system.properties</value>

我使用的是Mac OS,因此我们将配置存储为jar文件,存储在/ Library / Java / Extension下。因此,默认情况下,java直接将类路径引用到该位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM