From 0543036ec95c7f172a5ced2ac11389e4e05f7825 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 19 Mar 2010 12:39:34 +0000 Subject: [PATCH] FooConfig, Foo, Bar, and BarFactory are now public static classes in order to avoid a bug with JDT/Spring IDE where the classes cannot be found in the XML application context. --- .../annotation/Spr6602Tests-context.xml | 11 ++-- .../context/annotation/Spr6602Tests.java | 65 +++++++++++-------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests-context.xml b/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests-context.xml index 451fe7f36a..a6eb150f46 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests-context.xml +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests-context.xml @@ -1,12 +1,11 @@ - - - + + - - + + diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests.java index fa2c3a6b0e..50453f6b5d 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/Spr6602Tests.java @@ -36,58 +36,67 @@ public class Spr6602Tests { public void testXmlBehavior() throws Exception { doAssertions(new ClassPathXmlApplicationContext("Spr6602Tests-context.xml", Spr6602Tests.class)); } - + @Test public void testConfigurationClassBehavior() throws Exception { doAssertions(new AnnotationConfigApplicationContext(FooConfig.class)); } - + private void doAssertions(ApplicationContext ctx) throws Exception { Foo foo = ctx.getBean(Foo.class); - + Bar bar1 = ctx.getBean(Bar.class); Bar bar2 = ctx.getBean(Bar.class); assertThat(bar1, is(bar2)); assertThat(bar1, is(foo.bar)); - + BarFactory barFactory1 = ctx.getBean(BarFactory.class); BarFactory barFactory2 = ctx.getBean(BarFactory.class); assertThat(barFactory1, is(barFactory2)); - + Bar bar3 = barFactory1.getObject(); Bar bar4 = barFactory1.getObject(); assertThat(bar3, is(not(bar4))); } - -} + @Configuration + public static class FooConfig { + @Bean + public Foo foo() throws Exception { + return new Foo(barFactory().getObject()); + } -@Configuration -class FooConfig { - public @Bean Foo foo() throws Exception { - return new Foo(barFactory().getObject()); - } - - public @Bean BarFactory barFactory() { - return new BarFactory(); + @Bean + public BarFactory barFactory() { + return new BarFactory(); + } } -} -class Foo { final Bar bar; public Foo(Bar bar) { this.bar = bar; } } -class Bar { } + public static class Foo { + final Bar bar; -class BarFactory implements FactoryBean { - - public Bar getObject() throws Exception { - return new Bar(); + public Foo(Bar bar) { + this.bar = bar; + } } - public Class getObjectType() { - return Bar.class; + public static class Bar { } - - public boolean isSingleton() { - return true; + + public static class BarFactory implements FactoryBean { + + public Bar getObject() throws Exception { + return new Bar(); + } + + public Class getObjectType() { + return Bar.class; + } + + public boolean isSingleton() { + return true; + } + } -} +} \ No newline at end of file