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 451fe7f36a14bbfbedbff23662f4c7eed546a57b..a6eb150f4662313f6d7a76c551dad640ce9282bf 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 fa2c3a6b0e07ad119a16dd037d64802365d781df..50453f6b5d27c12e61355a92ce8335ef460acadf 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