Spring boot could not resolve placeholder in string
Fixed by adding these lines to the pom under the <resources>
section
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
What I don't fully understand is the need for doing this.
a) I can run this on an external app server without having to add this line and the app reads application.properties
just fine.
b) I can run the app as a standalone java application in eclipse (i.e., without having to build the app through maven) and it reads application.properties
just fine
c) isn't spring-boot supposed to read it by default regardless? (as shown by the two cases above?)
Thanks everyone for their help. hopefully this will help others.
Could not resolve placeholder in string value
In your configuration you have 2 PropertySourcesPlaceholderConfigurer
instances.
applicationContext.xml
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="environment">
<bean class="org.springframework.web.context.support.StandardServletEnvironment"/>
</property>
</bean>
infraContext.xml
<context:property-placeholder location="classpath:context-core.properties"/>
By default a PlaceholderConfigurer
is going to fail-fast, so if a placeholder cannot be resolved it will throw an exception. The instance from the applicationContext.xml
file has no properties and as such will fail on all placeholders.
Solution: Remove the one from applicationContext.xml as it doesn't add anything it only breaks things.
Spring could not resolve placeholder in value
There was one more config.properties in test directory.
getting Could not resolve placeholder while reading yml values in spring boot
check your placeholder is Tab or Space ? make sure no Tab in your yml file.
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder
Check that those properties are actually defined in application.properties
. There is also an application-aws.properties
file, if the properties are only in that file then you will need to tell Spring Boot to enable the aws
profile with SPRING_PROFILES_ACTIVE=aws
, or add the aws
properties with empty values in application.properties
.
If no Spring Boot profile is activated, it will only use the properties defined in application.properties
.
If you enable the aws
profile, it will use use properties from application.properties
as defaults, and then any matching properties defined in application-aws.properties
will override those from application.properties
if defined.
If what you are trying to do it only use those AWS properties when deployed to AWS, then you might need to make a Configuration object that holds those properties in it(which is a better practice than including properties with @Value
in code), and make the AmazonS3
bean creation conditional on those properties being set.
Given that your project structure is a standard Maven structure, convention over configuration should apply and there should be no need to try and explicitly include application.properties
with additional class path configuration. I.e everything under /src/main/resources
should be available on the class path and to the application at runtime.
@Value "Could not resolve placeholder" in Spring Boot Test
You need to add
@PropertySource("classpath:application.properties")
to your class, so it will pick your normal configurations.
If you need different configurations for test you can add
@TestPropertySource(locations="classpath:test.properties")
If not just copy paste your config file to test/resources
folder, then boot will pick from there.
See this.
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'some.other.property' in value "${some.other.property}"
I finally found the fix myself. Seems that the client bootstrapping doesn't occur automatically in new Spring Cloud release, instead we need to add following dependency and explicitly mention the bootstrapping in bootstrap.xml in the config-client.
Add the dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
And then I just added the following line in bootstrap.xml of my config-client and it worked magically.
spring.cloud.bootstrap.enabled=true
I got this from this link:
Spring Cloud Config: client doesn't attempt to connect to the config server:
Thank you so much guys for your help and contribution! Thanks @Bragolgirith for the fix. Hope this helps people and save their time.
Related Topics
Redirecting to a Servlet from a Jsp on Button Click
Finding Repeated Words on a String and Counting the Repetitions
How to Call a Function from Other Activity Android
Find Difference Between Two Strings
Rounding to the Nearest Hundered-Thousandths
How to Split a String Between Letters and Digits (Or Between Digits and Letters)
Cannot Construct Instance of 'Java.Time.Localdate' - Spring Boot, Elasticseach, Jackson
How to Download a Pdf File in Chrome Using Selenium Webdriver
How to Mock a Rest Template Exchange
How to Check If an Excel Cell Is Empty Using Apache Poi
Get Unique Values from Arraylist in Java
Save Child Objects Automatically Using JPA Hibernate
Write to Text File from Multiple Threads
Printing a Statement Only Once in a While Loop
How to Create a Spring JPA Repository Findby Query Using a Property That Contains a Keyword
How to Trim White Space from All Elements in Array
Java Stream:Create New List from 2 Lists Keeping Only Matching Values