-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Injection of List<Resource> is inconsistent with Resource[] #24845
Comments
Thanks for raising the issue. I've been able to reproduce this against package org.springframework.test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
@SpringJUnitConfig
class ResourceInjectionTests {
@BeforeAll
static void setup() throws IOException {
List<File> files = Arrays.asList(new File("/tmp", "a.text"), new File("/tmp", "b.text"));
for (File file : files) {
file.createNewFile();
file.deleteOnExit();
}
}
@Value("file:/tmp/*.text")
Resource[] resourceArray;
@Value("file:/tmp/*.text")
List<Resource> resourceList;
@Test
void testInjection() {
assertThat(resourceArray).as("array").hasSize(2); // two FileSystemResource
assertThat(resourceList).as("list").hasSize(2); // one FileUrlResource
}
@Configuration
static class Config {
}
} I assume it has something to do with the fact that a |
Indeed, the difference is that a The former internally uses a |
This reminds me that Is that intentional? |
@encircled, That is currently not supported, but feel free to open a new issue to start a discussion on the topic. |
Nevermind my prev comment, I just realized it is actually possible to do so by adding the |
Team Decision: Assigned to 5.x backlog as a potential enhancement. |
Normally it's safe to change type from array to list, but it's not for
Resource
.here is the full test
The text was updated successfully, but these errors were encountered: