Questions tagged [configurationproperties]

89 questions
13
votes
1 answer

Polymorphic configuration properties in Spring Boot

I would like to use polymorphic configuration properties on Spring, using Spring's @ConfigurationProperties annotation. Suppose we have the following POJO classes. public class Base { private String sharedProperty; public String…
Buğra Ekuklu
  • 3,049
  • 2
  • 17
  • 28
7
votes
2 answers

Is it possible to make Spring Boot Configuration Processor work correctly with maps which values are complex structures (in Intellij IDEA)?

Source code that reproduces the problem: link. Suppose I have this kind of structure of configuration properties: @Data @ConfigurationProperties(prefix = "props") public class ConfigProperties { private String testString; …
amseager
  • 5,795
  • 4
  • 24
  • 47
7
votes
5 answers

Spring Boot read properties without prefix to a map

I need to read all properties in application.properties file in a map In the code below the property test has the respective value but the map is empty. How can I fill "map" with the values in the application.properties file without adding a prefix…
Jorge Miralles
  • 73
  • 1
  • 1
  • 3
5
votes
1 answer

Custom Spring Boot 3 Starter does not create ConfigurationProperties beans

I am creating a Maven artifact with following classes and configuration in custom Spring Starter project: @ConfigurationProperties(prefix = "commons.time.formats") @Getter @Setter public class TimeFormatConf { ...…
5
votes
1 answer

Spring calls noargs constructor on java record for @ConfigurationProperties

I'm pulling my hair out here. I want to use a Java record for my @ConfigurationProperties, providing default values to unspecified config properties. Here is a very simple example: @ConfigurationProperties(prefix = "myconfig") public record…
BoomShaka
  • 1,571
  • 7
  • 27
  • 40
5
votes
2 answers

How to use @ConfigurationProperties with Kotlin

I have this custom object: data class Pair( var first: String = "1", var second: String = "2" ) And now I want to autowire it with my application.yml: my-properties: my-integer-list: - 1 - 2 - 3 my-map: - "abc": "123" -…
rado
  • 5,720
  • 5
  • 29
  • 51
4
votes
1 answer

How to read List of Strings in spring application.yml file into Immutables object?

Here's a sample application.yml file myapp: resource: teststring: "string" testlist: - "apple" - "banana" Here's my immutables configuration class import org.immutables.value.Value.Immutable; import…
kane
  • 5,465
  • 6
  • 44
  • 72
4
votes
0 answers

Thread safety of refreshing configuration properties using @RefreshScope

I have a bean annotated with @ConfigurationProperties where I have the needed properties by the application bound. I have also annotated the class with @RefreshScope so I can refresh any config properties that change at runtime. A basic version…
4
votes
0 answers

Springboot / Kotlin: Best Practice to test a Class that injects another @ConfigurationProperties class

I have a project in Kotlin. I created a @ConfigurationProperties class and I would like to know the best practices for unit tests. The following is my properties class: @ConstructorBinding @ConfigurationProperties(prefix = "myapp") data class…
4
votes
1 answer

Using Spring Boot 2.2.0's @ConstructorBinding for multiple Beans

So I'm very excited about the new @ConstructorBinding feature but I have a question about how it interacts with @ConfigurationProperties. It is possible to declare multiple beans of the same type with configuration properties by changing the prefix,…
B-ron
  • 181
  • 2
  • 5
3
votes
1 answer

@ConstructorBinding seems not to work in Spring Boot 2.5.4

I'm using Spring Boot 2.5.4 and am trying to initialize an immutable class from properties: @Configuration @ConfigurationProperties("test") public class Config { public final String foo; @ConstructorBinding public Config(String foo)…
OhleC
  • 2,821
  • 16
  • 29
3
votes
1 answer

Test on Spring configuration properties reading an external YML file doesn't work

I'm working with Spring Boot 2.4.8, and I'm reading into a bean the information read from an external YML file: @Component @ConfigurationProperties(prefix = "my.conf") @PropertySource(value = "classpath:ext.yml", factory =…
3
votes
1 answer

Spring test property override replaces whole array element

I am using @ConfigurationProperties @Getter @Setter @ConfigurationProperties(prefix = "my") @Component public class MyProperties { private Nested single; private List many; } @Getter @Setter public class Nested { private String…
sinedsem
  • 5,413
  • 7
  • 29
  • 46
3
votes
2 answers

@DataJpaTest: how to stop loading unneeded @ConfigurationProperties

In a SpringBoot (2.2.1,2.2.2) application a sliced @DataJpaTest doesn't run because a bean holding @ConfigurationProperties could not be created. The test: @DataJpaTest public class FooCustomerServiceTest { @Autowired FooCustomerRepository…
2
votes
2 answers

Spring Boot can no longer bind configuration properties when migrating to version 3+ in Kotlin

After migrating an app to Spring Boot 3.0.1 the configuration properties can no longer be loaded from the application.yml file. It does not work on any class that previously was ok. The following configuration spec started failing with uninitialized…
1
2 3 4 5 6