ConditionalOnClass found required class

If auto configuration is enabled in spring boot application and the ConditionalOnClass property is modified, the dependent class shows in auto configuration report



Auto Configuration Report

Negative matches:
 JpaBaseConfiguration.JpaWebConfiguration:
         Did not match:
          - @ConditionalOnProperty (spring.jpa.open-in-view=true) found different value in property 'open-in-view' (OnPropertyCondition)
       Matched:
          - @ConditionalOnClass found required class 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
          - found 'session' scope (OnWebApplicationCondition)
Positive matches:
 JpaBaseConfiguration.JpaWebConfiguration matched:
       - @ConditionalOnClass found required class 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
       - found 'session' scope (OnWebApplicationCondition)


Root Cause

The conditional configuration specified in annotation @ConditionalOnClass has been changed. So the dependent class is shown in the auto configuration report.



Reason

@ConditionalOnClass -  Conditional that only matches when the specified classes are on the classpath.

Explanation

In the above example, a configuration ‘spring.jpa.open-in-view’ is modified in application.properties. This property has dependency class ‘org.springframework.web.servlet.config.annotation.WebMvcConfigurer’ based on condition.

The specified class will be available in class path if the condition returns true based on configuration value.

The specified class will not be available in class path if the condition returns false. Condition checks based on configuration value.



Session Scope

If the spring boot runs web application then this scope will be applicable. If it is a spring boot web application, the specified class will be loaded in session scope



Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *