Moved the code samples for BeanDefinitionOverrideException to a new module.
This commit is contained in:
@@ -31,4 +31,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks)
|
||||
- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot)
|
||||
- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation)
|
||||
- [The BeanDefinitionOverrideException in Spring Boot](https://www.baeldung.com/spring-boot-bean-definition-override-exception)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.baeldung.beandefinitionoverrideexception;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {TestConfiguration1.class, TestConfiguration2.class}, properties = {"spring.main.allow-bean-definition-overriding=true"})
|
||||
public class SpringBootBeanDefinitionOverrideExceptionIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void whenBeanOverridingAllowed_thenTestBean2OverridesTestBean1() {
|
||||
Object testBean = applicationContext.getBean("testBean");
|
||||
|
||||
assertThat(testBean.getClass()).isEqualTo(TestConfiguration2.TestBean2.class);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.baeldung.beandefinitionoverrideexception;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class TestConfiguration1 {
|
||||
|
||||
class TestBean1 {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TestBean1 testBean() {
|
||||
return new TestBean1();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.baeldung.beandefinitionoverrideexception;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class TestConfiguration2 {
|
||||
|
||||
class TestBean2 {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TestBean2 testBean() {
|
||||
return new TestBean2();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user