Aisteru Firë
Aisteru Firë

Reputation: 218

Spring: check if annotation is used but bean is not present

I have some homemade annotation (let us call it @A) that can be used on RequestMappings to work with some OncePerRequestFilter (called MyFilter here).

I have made an autoconfiguration to conditionally create the MyFilter bean, and I now wish to perform the following check: if @A is used on at least one of my request mappings, throw an error if no instance of MyFilter is available.

In trying so, I have tried:

Now, the only idea I have left is to create a dummy bean that depends on RequestMappingHandlerMapping and Optional<MyFilter>, and which goal is just to throw an exception if the conditions are satisfied.

Is there a clean way of performing something like this?

Upvotes: 0

Views: 23

Answers (0)

Related Questions