Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* @author Jakub Kubrynski
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Jorge Cordoba
* @see ConditionalOnBean
* @see ConditionalOnMissingBean
* @see ConditionalOnSingleCandidate
Expand Down Expand Up @@ -387,7 +388,7 @@ private static class Spec<A extends Annotation> {

private final ClassLoader classLoader;

private final Class<?> annotationType;
private final Class<? extends Annotation> annotationType;

private final Set<String> names;

Expand Down Expand Up @@ -581,11 +582,11 @@ Set<Class<?>> getParameterizedContainers() {
}

ConditionMessage.Builder message() {
return ConditionMessage.forCondition(ConditionalOnBean.class, this);
return ConditionMessage.forCondition(this.annotationType, this);
}

ConditionMessage.Builder message(ConditionMessage message) {
return message.andCondition(ConditionalOnBean.class, this);
return message.andCondition(this.annotationType, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Collection;
import java.util.Date;
import java.util.function.Consumer;

Expand Down Expand Up @@ -57,6 +58,7 @@
* @author Phillip Webb
* @author Jakub Kubrynski
* @author Andy Wilkinson
* @author Jorge Cordoba
*/
@SuppressWarnings("resource")
public class ConditionalOnMissingBeanTests {
Expand Down Expand Up @@ -135,6 +137,16 @@ void testAnnotationOnMissingBeanConditionWithEagerFactoryBean() {
assertThat(context.getBean("foo")).isEqualTo("foo");
});
}
@Test
void testOnMissingBeanConditionOutputShouldNotContainConditionalOnBeanClassInMessage() {
this.contextRunner.withUserConfiguration(ConditionalOnMissingBeanTests.OnBeanNameConfiguration.class).run((context) -> {
Collection<ConditionEvaluationReport.ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport
.get(context.getSourceApplicationContext().getBeanFactory()).getConditionAndOutcomesBySource()
.values();
String message = conditionAndOutcomes.iterator().next().iterator().next().getOutcome().getMessage();
assertThat(message).doesNotContain("@ConditionalOnBean (names: foo; SearchStrategy: all) did not find any beans");
});
}

@Test
void testOnMissingBeanConditionWithFactoryBean() {
Expand Down