-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to bind properties to List<Resource> #38556
Comments
It's a spring boot regression introduced by 0e3a196. import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileUrlResource;
import org.springframework.core.io.Resource;
import org.springframework.test.context.TestPropertySource;
@SpringBootTest
@EnableConfigurationProperties(ResourcesInjectionTests.ConfigProperties.class)
@TestPropertySource(properties = "resources=classpath:foo.properties,file:./bar.properties")
public class ResourcesInjectionTests {
@Autowired
ConfigProperties configProperties;
@Test
void test() {
assertThat(configProperties.resources).hasSize(2);
assertThat(configProperties.resources.get(0)).isInstanceOf(ClassPathResource.class);
assertThat(configProperties.resources.get(1)).isInstanceOf(FileUrlResource.class);
}
@ConfigurationProperties
record ConfigProperties(List<Resource> resources) {
}
}
This test case works fine with 3.1.6 but failed with 3.2.0. |
There's also a related problem with With Spring Boot 3.1.6 you get |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
It's fixed by spring-projects/spring-framework#31700. |
Hello same probleme here : I have two databases mongoDb, and in version 3.1.5 everything was fine and now i have this error : Failed to bind properties under 'spring.data.mongodb' to com.adeo.sofi.configuration.CustomMongoProperties$MongoDbProperties: Here my configuration data:
mongodb:
sofi:
database: ***
uri: ****
referential:
database: ***
uri: **** |
@jagneray without knowing anything about your |
Here's a minimal example that tries to capture the status of things both for the case described above and for the wildcard case that #15835 sought to address: package com.example.gh38556;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.io.Resource;
import com.example.gh38556.Gh38556Application.CoolConfigProperties;
@SpringBootApplication
@EnableConfigurationProperties(CoolConfigProperties.class)
public class Gh38556Application {
@Value("${cool.list}")
private List<Resource> list;
@Value("${cool.array}")
private Resource[] array;
@Value("${cool.wildcard-list}")
private List<Resource> wildcardList;
@Value("${cool.wildcard-array}")
private Resource[] wildcardArray;
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Gh38556Application.class,
"--cool.list=classpath:foo.properties,file:./bar.properties",
"--cool.array=classpath:foo.properties,file:./bar.properties",
"--cool.wildcard-list=classpath*:com/example/**/*.class",
"--cool.wildcard-array=classpath*:com/example/**/*.class");
CoolConfigProperties coolConfigProperties = context.getBean(CoolConfigProperties.class);
System.out.println("@ConfigurationProperties:");
System.out.println(" " + coolConfigProperties.list());
System.out.println(" " + Arrays.toString(coolConfigProperties.array()));
System.out.println(" " + coolConfigProperties.wildcardList());
System.out.println(" " + Arrays.toString(coolConfigProperties.wildcardArray()));
Gh38556Application app = context.getBean(Gh38556Application.class);
System.out.println("@Value:");
System.out.println(" " + app.list);
System.out.println(" " + Arrays.toString(app.array));
System.out.println(" " + app.wildcardList);
System.out.println(" " + Arrays.toString(app.wildcardArray));
}
@ConfigurationProperties(prefix = "cool")
record CoolConfigProperties(List<Resource> list, Resource[] array,
List<Resource> wildcardList, Resource[] wildcardArray) {}
} With Spring Boot 3.1.6, the following is output:
With Spring Boot 3.2.1-SNAPSHOT and Spring Framework 6.1.2-SNAPSHOT, the following is output:
The behavior of |
@snicoll @jhoeller do you have a feel for if and when spring-projects/spring-framework#31700 might land? |
@wilkinsona this should be available in Spring Framework |
With the latest
Things are now consistent and comma-separated values are being handled. Thanks, @snicoll and @quaff. I'll close this one in favour of the changes that have been made in Framework. |
Hello friends. While upgrading to spring-boot v3.2.0, I believe I found a regression in the binding of properties to a
List<org.springframework.core.io.Resource>
. A small sample will demonstrate:For this example, we will set an environment variable
COOL_RESOURCES=classpath:foo.properties,file:./bar.properties
.Resources are bound to ConfigurationProperties as expected when running with spring-boot v3.1.6:
However spring-boot v3.2.0 will fail to start:
The text was updated successfully, but these errors were encountered: