Questions tagged [spring-properties]
166 questions
319
votes
17 answers
Reading a List from properties file and load with Spring annotation @Value
I want to have a list of values in a .properties file, i.e.:
my.list.of.strings=ABC,CDE,EFG
And to load it in my class directly, i.e.:
@Value("${my.list.of.strings}")
private List myList;
As I understand, an alternative of doing this is to…

JackDev
- 11,003
- 12
- 51
- 68
90
votes
15 answers
Spring @Value is not resolving to value from property file
I've had this working in some other project before, I am just re-doing the same thing but for some reason it's not working. The Spring @Value is not reading from property file, but instead it's taking the value…

TS-
- 4,311
- 8
- 40
- 52
73
votes
8 answers
Spring Boot access static resources missing scr/main/resources
I am working on a Spring Boot application. I need to parse an XML file (countries.xml) on start. The problem is that I do not understand where to put it so that I could access it.
My folders structure is…

lenach87
- 949
- 3
- 11
- 18
57
votes
3 answers
Spring @Value escape colon(:) in default value
I have the following property annotated with @Value. I have a default value defined using the default separator of ':"
@Value("${prop.url:http://myurl.com}")
Is there a way to escape the ':' in http://myurl.com or do I have to define a different…

mjj1409
- 3,075
- 6
- 28
- 28
43
votes
6 answers
Spring @Value TypeMismatchException:Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'
I want to use the @Value annotation to inject a Double property such as:
@Service
public class MyService {
@Value("${item.priceFactor}")
private Double priceFactor = 0.1;
// ...
and using Spring property placeholder (Properties…

guilhebl
- 8,330
- 10
- 47
- 66
25
votes
4 answers
Spring Boot bind @Value to Enum case insensitive
Enum
public enum Property {
A,
AB,
ABC;
}
Field
@Value("${custom.property}")
protected Property property;
application.properties (lower case)
custom.property=abc
When I'm running application I have an error:
Cannot convert value of…

Mikhail Kholodkov
- 23,642
- 17
- 61
- 78
19
votes
3 answers
Specifying relative path in application.properties in Spring
Is there a way we can lookup file resources using relative path in application.properties file in Spring boot application as specified below
spring.datasource.url=jdbc:hsqldb:file:${project.basedir}/db/init

Somasundaram Sekar
- 5,244
- 6
- 43
- 85
19
votes
4 answers
Spring @Value("${}") often null
I'm using Spring Boot application. In some @Component class @Value fields are loaded, instead on other classes they are always null.
Seems that @Value(s) are loaded after my @Bean/@Component are created.
I need to load some values from a properties…

drenda
- 5,846
- 11
- 68
- 141
16
votes
5 answers
spring application.yml reference list from another property
I have property file application-dev.yml with content:
spring.profiles: dev
config.some.value:
- ELEMENT1
- ELEMENT2
and another application-staging.yml with content:
spring.profiles: staging
config.some.value:
- ELEMENT1
- ELEMENT2
- ELEMENT3
so…

Mateusz
- 1,149
- 1
- 16
- 33
11
votes
1 answer
What is diff between spring.profiles.active vs spring.config.activate.on-profile?
What is exact difference between spring.profiles.active and spring.config.activate.on-profile?
"WARN","msg":"Property 'spring.profiles' imported from location 'class path resource [application.yaml]' is invalid and should be replaced with…

Prashant kamble
- 259
- 2
- 4
- 11
8
votes
1 answer
Set Spring boot yaml configuration list property via environment variables
I am configuring my Spring Boot application with an application.yml file:
foo:
bar: foobar
foolist:
- bar: foobar1
baz: foobaz1
- bar: foobar1
baz: foobaz1
I can easily set the foo.bar value with an environment variable, e.g.
export…

feob
- 1,930
- 5
- 19
- 31
8
votes
2 answers
Using @Value with condition in spring in order to map value to string
I have a application.properites file with the following:
xxx.xxx = sandbox
xxx.sandbox = 123
xxx.production = 456
I would like to map to a string value 123 in case xxx.xxx == sandbox and 456 in case xxx.xxx == production
...
public class temp {
…

USer22999299
- 5,284
- 9
- 46
- 78
7
votes
1 answer
Can the Spring active profiles be set through a property file?
I want to be able to read the active profiles from a property file so that different environments (dev,prod etc) can be configured with different profiles in a Spring MVC based web application. I know that the active profiles can be set through JVM…

Navin Viswanath
- 894
- 2
- 13
- 22
6
votes
4 answers
How to bind a property with space to Map key in Spring application.properties file?
Given an application.properties file:
myProperties.map.key1=value1
myProperties.map.key2=value2
myProperties.map.key with space=value3
And the properties class:
@ConfigurationProperties
public class MyProperties {
private Map…

user1589188
- 5,316
- 17
- 67
- 130
5
votes
0 answers
@ConstructorBinding configuration not triggering validation when implementing the Validator interface
I'm using spring-boot-starter-parent version 2.4.4.
I'm experimenting with validation on Typed Configuration using @ConstructorBinding and without.
Here's a Typed Config that gets validated and correctly stops the app from running. It's not using…

nevvermind
- 3,302
- 1
- 36
- 45