之前写了一个condition,实现了org.springframework.context.annotation.Condition接口,但是发现matches方法执行了3次。
原因在于判断是否跳过是,会去判断是否实现了org.springframework.context.annotation.ConfigurationCondition接口,不实现org.springframework.context.annotation.ConfigurationCondition接口则ConfigurationPhase为null,如果为null则会执行一次matches方法。如果不为null,且不为org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.PARSE_CONFIGURATION则不会执行这一次。
解决办法:实现 org.springframework.context.annotation.ConfigurationCondition接口,将ConfigurationPhase设为ConfigurationPhase.PARSE_CONFIGURATION。