Could not resolve Spring property placeholder

前端 未结 7 2336
有刺的猬
有刺的猬 2020-11-27 15:13

I have my config:





        
相关标签:
7条回答
  • 2020-11-27 15:26

    It's definitely not a problem with propeties file not being found, since in that case another exception is thrown.

    Make sure that you actually have a value with key idm.url in your idm.properties.

    0 讨论(0)
  • 2020-11-27 15:26

    make sure your properties file exist in classpath directory but not in sub folder of your classpath directory. if it is exist in sub folder then write as below classpath:subfolder/idm.properties

    0 讨论(0)
  • 2020-11-27 15:26

    the following property must be added in the gradle.build file

    processResources {
        filesMatching("**/*.properties") {
            expand project.properties
        }
    }
    
    

    Additionally, if working with Intellij, the project must be re-imported.

    0 讨论(0)
  • 2020-11-27 15:32

    You may have more than one org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in your application. Try setting a breakpoint on the setLocations method of the superclass and see if it's called more than once at application startup. If there is more than one org.springframework.beans.factory.config.PropertyPlaceholderConfigurer, you might need to look at configuring the ignoreUnresolvablePlaceholders property so that your application will start up cleanly.

    0 讨论(0)
  • 2020-11-27 15:41

    Ensure 'idm.url' is set in property file and the property file is loaded

    0 讨论(0)
  • 2020-11-27 15:45

    Your property file location is classpath:idm.properties

    This is rather unusual, it means that idm.properties must be located either at the top level of WEB-INF/classes or at the top-level of one of the jars inside WEB-INF/lib. Usually it's good practice to either use a dedicated folder for properties or keep them close to the context files that use them.

    So my suggestion is this: Is your properties file perhaps next to your context file? If so, it's not on the classpath (see this question: Is WEB-INF in the CLASSPATH?).

    The classpath: prefix maps to a ClassPathResource, but you probably need a ServletContextResource, and you'll get that from a WebApplicationContext using the syntax without prefix:

    <context:property-placeholder location="idm.properties" />
    

    Reference:

    • The ResourceLoader
      (describes how different ApplicationContext types handle resources without prefix)
    • The PropertyPlaceholderConfigurer mechanism
      (describes the <context:property-placeholder> mechanism)
    0 讨论(0)
提交回复
热议问题