|
|
@ -16,10 +16,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.diagnostics.analyzer;
|
|
|
|
package org.springframework.boot.diagnostics.analyzer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionOverrideException;
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionOverrideException;
|
|
|
|
import org.springframework.boot.diagnostics.FailureAnalysis;
|
|
|
|
import org.springframework.boot.diagnostics.FailureAnalysis;
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContextInitializer;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
@ -43,6 +46,18 @@ class BeanDefinitionOverrideFailureAnalyzerTests {
|
|
|
|
assertThat(description).contains(FirstConfiguration.class.getName());
|
|
|
|
assertThat(description).contains(FirstConfiguration.class.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void analyzeBeanDefinitionOverrideExceptionWithDefinitionsWithNoResourceDescription() {
|
|
|
|
|
|
|
|
FailureAnalysis analysis = performAnalysis((context) -> {
|
|
|
|
|
|
|
|
context.registerBean("testBean", String.class, (Supplier<String>) String::new);
|
|
|
|
|
|
|
|
context.registerBean("testBean", String.class, (Supplier<String>) String::new);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
String description = analysis.getDescription();
|
|
|
|
|
|
|
|
assertThat(description)
|
|
|
|
|
|
|
|
.isEqualTo("The bean 'testBean' could not be registered. A bean with that name has already"
|
|
|
|
|
|
|
|
+ " been defined and overriding is disabled.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private FailureAnalysis performAnalysis(Class<?> configuration) {
|
|
|
|
private FailureAnalysis performAnalysis(Class<?> configuration) {
|
|
|
|
BeanDefinitionOverrideException failure = createFailure(configuration);
|
|
|
|
BeanDefinitionOverrideException failure = createFailure(configuration);
|
|
|
|
assertThat(failure).isNotNull();
|
|
|
|
assertThat(failure).isNotNull();
|
|
|
@ -63,6 +78,28 @@ class BeanDefinitionOverrideFailureAnalyzerTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private FailureAnalysis performAnalysis(
|
|
|
|
|
|
|
|
ApplicationContextInitializer<AnnotationConfigApplicationContext> initializer) {
|
|
|
|
|
|
|
|
BeanDefinitionOverrideException failure = createFailure(initializer);
|
|
|
|
|
|
|
|
assertThat(failure).isNotNull();
|
|
|
|
|
|
|
|
return new BeanDefinitionOverrideFailureAnalyzer().analyze(failure);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BeanDefinitionOverrideException createFailure(
|
|
|
|
|
|
|
|
ApplicationContextInitializer<AnnotationConfigApplicationContext> initializer) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
context.setAllowBeanDefinitionOverriding(false);
|
|
|
|
|
|
|
|
initializer.initialize(context);
|
|
|
|
|
|
|
|
context.refresh();
|
|
|
|
|
|
|
|
context.close();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (BeanDefinitionOverrideException ex) {
|
|
|
|
|
|
|
|
return ex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Import({ FirstConfiguration.class, SecondConfiguration.class })
|
|
|
|
@Import({ FirstConfiguration.class, SecondConfiguration.class })
|
|
|
|
static class BeanOverrideConfiguration {
|
|
|
|
static class BeanOverrideConfiguration {
|
|
|
|