|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -23,6 +23,7 @@ import org.junit.Test; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
|
|
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.*; |
|
|
|
import static org.hamcrest.CoreMatchers.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
@ -58,6 +59,39 @@ public class BeanMethodPolymorphismTests { |
|
|
|
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void beanMethodOverridingOnASM() { |
|
|
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
|
|
|
|
ctx.registerBeanDefinition("config", new RootBeanDefinition(OverridingConfig.class.getName())); |
|
|
|
|
|
|
|
ctx.setAllowBeanDefinitionOverriding(false); |
|
|
|
|
|
|
|
ctx.refresh(); |
|
|
|
|
|
|
|
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
|
|
|
|
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString()); |
|
|
|
|
|
|
|
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void beanMethodOverridingWithNarrowedReturnType() { |
|
|
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
|
|
|
|
ctx.register(NarrowedOverridingConfig.class); |
|
|
|
|
|
|
|
ctx.setAllowBeanDefinitionOverriding(false); |
|
|
|
|
|
|
|
ctx.refresh(); |
|
|
|
|
|
|
|
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
|
|
|
|
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString()); |
|
|
|
|
|
|
|
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void beanMethodOverridingWithNarrowedReturnTypeOnASM() { |
|
|
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
|
|
|
|
ctx.registerBeanDefinition("config", new RootBeanDefinition(NarrowedOverridingConfig.class.getName())); |
|
|
|
|
|
|
|
ctx.setAllowBeanDefinitionOverriding(false); |
|
|
|
|
|
|
|
ctx.refresh(); |
|
|
|
|
|
|
|
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
|
|
|
|
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString()); |
|
|
|
|
|
|
|
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void beanMethodOverloadingWithoutInheritance() { |
|
|
|
public void beanMethodOverloadingWithoutInheritance() { |
|
|
|
|
|
|
|
|
|
|
|
@ -138,6 +172,26 @@ public class BeanMethodPolymorphismTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class ExtendedTestBean extends TestBean { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
|
|
|
static class NarrowedOverridingConfig extends BaseConfig { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean @Lazy |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public ExtendedTestBean testBean() { |
|
|
|
|
|
|
|
return new ExtendedTestBean() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String toString() { |
|
|
|
|
|
|
|
return "overridden"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
static class SuperConfig { |
|
|
|
static class SuperConfig { |
|
|
|
|
|
|
|
|
|
|
|
|