Apply array editor to collection of same element type as well

Closes gh-24845
This commit is contained in:
Juergen Hoeller
2023-08-03 17:55:54 +02:00
parent c3e18bc173
commit 84b3335e71
5 changed files with 43 additions and 19 deletions

View File

@@ -222,11 +222,12 @@ public class ClassPathXmlApplicationContextTests {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
Service service = ctx.getBean("service", Service.class);
assertThat(service.getResources()).containsExactlyInAnyOrder(contextA, contextB, contextC);
assertThat(service.getResourceSet()).containsExactlyInAnyOrder(contextA, contextB, contextC);
ctx.close();
}
@Test
void childWithProxy() throws Exception {
void childWithProxy() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
new String[] {CHILD_WITH_PROXY_CONTEXT}, ctx);
@@ -337,8 +338,7 @@ public class ClassPathXmlApplicationContextTests {
};
ResourceTestBean resource1 = (ResourceTestBean) ctx.getBean("resource1");
ResourceTestBean resource2 = (ResourceTestBean) ctx.getBean("resource2");
boolean condition = resource1.getResource() instanceof ClassPathResource;
assertThat(condition).isTrue();
assertThat(resource1.getResource()).isInstanceOf(ClassPathResource.class);
StringWriter writer = new StringWriter();
FileCopyUtils.copy(new InputStreamReader(resource1.getResource().getInputStream()), writer);
assertThat(writer.toString()).isEqualTo("contexttest");

View File

@@ -118,7 +118,7 @@ class ConversionServiceFactoryBeanTests {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(fileName, getClass());
ResourceTestBean tb = ctx.getBean("resourceTestBean", ResourceTestBean.class);
assertThat(resourceClass.isInstance(tb.getResource())).isTrue();
assertThat(tb.getResourceArray()).isNotEmpty();
assertThat(tb.getResourceArray()).hasSize(1);
assertThat(resourceClass.isInstance(tb.getResourceArray()[0])).isTrue();
assertThat(tb.getResourceMap()).hasSize(1);
assertThat(resourceClass.isInstance(tb.getResourceMap().get("key1"))).isTrue();

View File

@@ -16,6 +16,8 @@
package org.springframework.context.support;
import java.util.Set;
import org.springframework.beans.factory.BeanCreationNotAllowedException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
@@ -37,6 +39,8 @@ public class Service implements ApplicationContextAware, MessageSourceAware, Dis
private Resource[] resources;
private Set<Resource> resourceSet;
private boolean properlyDestroyed = false;
@@ -65,6 +69,14 @@ public class Service implements ApplicationContextAware, MessageSourceAware, Dis
return resources;
}
public void setResourceSet(Set<Resource> resourceSet) {
this.resourceSet = resourceSet;
}
public Set<Resource> getResourceSet() {
return resourceSet;
}
@Override
public void destroy() {