Spring Could not Resolve placeholder

后端 未结 8 2058
说谎
说谎 2020-12-08 10:29

I\'m fairly new to spring so excuse me if this is a dumb question. When I try to launch a program I get the following error: java.lang.IllegalArgumentException: Could

相关标签:
8条回答
  • 2020-12-08 11:12

    I know It is an old message , but i want to add my case.

    If you use more than one profile(dev,test,prod...), check your execute profile.

    0 讨论(0)
  • 2020-12-08 11:18

    in my case, the war file generated didn't pick up the properties file so had to clean install again in IntelliJ editor.

    0 讨论(0)
  • 2020-12-08 11:22

    Hopefully it will be still helpful, the application.properties (or application.yml) file must be in both the paths:

    • src/main/resource/config
    • src/test/resource/config

    containing the same property you are referring

    0 讨论(0)
  • 2020-12-08 11:23

    For properties that need to be managed outside of the WAR:

    <context:property-placeholder location="file:///C:/application.yml"/>
    

    For example if inside application.yml are name and id

    Then you can create bean in runtime inside xml spring

    <bean id="id1" class="my.class.Item">
        <property name="name" value="${name}"/>
        <property name="id" value="${id}"/>
    </bean>
    
    0 讨论(0)
  • 2020-12-08 11:26

    If you are using Spring 3.1 and above, you can use something like...

    @Configuration
    @PropertySource("classpath:foo.properties")
    public class PropertiesWithJavaConfig {
    
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
      return new PropertySourcesPlaceholderConfigurer();
    }
    }
    

    You can also go by the xml configuration like...

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    
      <context:property-placeholder location="classpath:foo.properties" />
    
      </beans>
    

    In earlier versions.

    0 讨论(0)
  • 2020-12-08 11:27

    You are not reading the properties file correctly. The propertySource should pass the parameter as: file:appclient.properties or classpath:appclient.properties. Change the annotation to:

    @PropertySource(value={"classpath:appclient.properties"})
    

    However I don't know what your PropertiesConfig file contains, as you're importing that also. Ideally the @PropertySource annotation should have been kept there.

    0 讨论(0)
提交回复
热议问题