Injection of List<Resource> is inconsistent with Resource[]
See original GitHub issueNormally it’s safe to change type from array to list, but it’s not for Resource
.
@Value("${resources:file:/tmp/*.text}")
Resource[] resourceArray; // multiple FileSystemResource
@Value("${resources:file:/tmp/*.text}")
List<Resource> resourceList; // only one FileUrlResource
here is the full test
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import test.ResourceInjectionTest.TestConfiguration;
@RunWith(SpringRunner.class)
@TestPropertySource(properties = { "resources=file:/tmp/*.text" })
@ContextConfiguration(classes = TestConfiguration.class)
public class ResourceInjectionTest {
private static File[] files;
@Autowired
private TestConfiguration testConfiguration;
@BeforeClass
public static void setup() throws IOException {
files = new File[2];
files[0] = new File("/tmp", "a.text");
files[1] = new File("/tmp", "b.text");
for (File f : files)
f.createNewFile();
}
@AfterClass
public static void cleanup() {
for (File f : files)
f.delete();
}
@Test
public void testInjection() {
assertEquals(2, testConfiguration.resourceArray.length); // two FileSystemResource
assertEquals(2, testConfiguration.resourceList.size()); // one FileUrlResource
}
static class TestConfiguration {
@Value("${resources}")
Resource[] resourceArray;
@Value("${resources}")
List<Resource> resourceList;
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Type of related field hr.employee.employee_id is inconsistent ...
hi all , iam trying to add a extra field in hr_emp module , but when i add the server is not starting...
Read more >license-manager CLI docs inconsistent : r/aws - Reddit
But in my AWS CLI, I see only these commands: create-license-configuration. delete-license-configuration. get-license-configuration. get ...
Read more >Extending Angular's $resource Service for a Consistent API
With this method, we can now inject our api service as a dependency and register our resource models with an easy one-line call:...
Read more >gcloud beta resource-config list-resource-types
Accelerate your digital transformation; Whether your business is early in its journey or well on its way to digital transformation, Google Cloud can...
Read more >Maven Websphere JNDI Resource Binding - Forums - IBM
InjectionProc E CWNEN0044E: A resource reference binding could not be found for ... in others it is codecoverageUI, I am making them consistent...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Indeed, the difference is that a
ResourceArrayPropertyEditor
is used to handle the array case; whereas, aCustomCollectionEditor
is used to handle the list case.The former internally uses a
ResourcePatternResolver
to expand the pattern into the 2 files in the filesystem; whereas, the latter simply treats the pattern as a simple string without expansion.Team Decision: Assigned to 5.x backlog as a potential enhancement.