注释类型 ConditionalOnSingleCandidate


  • @Target({TYPE,METHOD})
    @Retention(RUNTIME)
    @Documented
    @Conditional(org.springframework.boot.autoconfigure.condition.OnBeanCondition.class)
    public @interface ConditionalOnSingleCandidate
    Conditional that only matches when the specified bean class is already contained in the BeanFactory and a single candidate can be determined.

    The condition will also match if multiple matching bean instances are already contained in the BeanFactory but a primary candidate has been defined; essentially, the condition match if auto-wiring a bean with the defined type will succeed.

    The condition can only match the bean definitions that have been processed by the application context so far and, as such, it is strongly recommended to use this condition on auto-configuration classes only. If a candidate bean may be created by another auto-configuration, make sure that the one using this condition runs after.

    从以下版本开始:
    1.3.0
    • 可选元素概要

      可选元素 
      修饰符和类型可选元素说明
      SearchStrategysearch
      Strategy to decide if the application context hierarchy (parent contexts) should be considered.
      Stringtype
      The class type name of bean that should be checked.
      Class<?>value
      The class type of bean that should be checked.
    • 元素详细资料

      • value

        Class<?> value
        The class type of bean that should be checked. The condition match if the class specified is contained in the ApplicationContext and a primary candidate exists in case of multiple instances.

        This attribute may not be used in conjunction with type() , but it may be used instead of type().

        返回:
        the class type of the bean to check
        默认值:
        java.lang.Object.class
      • type

        String type
        The class type name of bean that should be checked. The condition matches if the class specified is contained in the ApplicationContext and a primary candidate exists in case of multiple instances.

        This attribute may not be used in conjunction with value(), but it may be used instead of value().

        返回:
        the class type name of the bean to check
        默认值:
        ""
      • search

        SearchStrategy search
        Strategy to decide if the application context hierarchy (parent contexts) should be considered.
        返回:
        the search strategy
        默认值:
        org.springframework.boot.autoconfigure.condition.SearchStrategy.ALL