How can i Write a custom Enable annotation for Interceptor in Spring boot app?
<p>Is it possible to write a custom enable annotation to enable a Interceptor for a Spring Boot app.</p>

<p>This is my code,</p>

<p><strong>Configuration</strong></p>

<pre><code>@Configuration
public class CustomConfig extends WebMvcConfigurerAdapter {

    @Autowired
    CustomInterceptor interceptor;

    @Override
      public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor);
    }

}
</code></pre>

<p><strong>Interceptor</strong></p>

<pre><code>@Component
public class CustomInterceptor implements HandlerInterceptor {

    @Override
    public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {

        System.err.println("Executed!!!afterCompletion");

    }

    @Override
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
            throws Exception {
        System.err.println("Executed!!!postHandle");

    }

    @Override
    public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
        // TODO Auto-generated method stub
        return true;
    }

}
</code></pre>

<p><strong>Custom Annotation</strong></p>

<pre><code>@Documented
@Retention(RUNTIME)
@Target(TYPE)
@Import(CustomConfig.class)
public @interface EnableCustomConfig {

}
</code></pre>

<p>I want to enable this interceptor only if this annotation</p>

<blockquote>
  <p>@EnableCustomConfig</p>
</blockquote>

<p>is present in the main class,</p>

<pre><code>@SpringBootApplication
@EnableAutoConfiguration
@EnableCustomConfig
public class CustomEnableApplication {

    public static void main(String[] args) {
        SpringApplication.run(CustomEnableApplication.class, args);
    }
}
</code></pre>

<p>Is this possible to achieve in spring boot? If yes, please can you let me know how to.</p>