I am using SpringBoot 3.0.0 with springdoc-openapi-starter-webmvc-ui 2.0.2. I have a annotation to be used with RestController
methods:
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Configuration and description of a endpoint.
*/
@ApiResponses
@Operation
@RequestMapping
@Target(ElementType.METHOD)
@Retention(RUNTIME)
@Documented
public @interface HorusEndpoint {
// other attributes
/**
* @return the array of the ApiResponses
* @see ApiResponses#value()
*/
@AliasFor(annotation = ApiResponses.class, attribute = "value")
ApiResponse[] responses() default {};
}
It works well in SpringBoot 3.0.0. However, I tried to upgrade to SpringBoot 3.0.1. When I start my application I had this error message:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\projects\horus\horus-back\user-management\target\classes\com\capgemini\engineering\horus\usermanagement\controllers\CollaboratorController.class]
...
Caused by: org.springframework.core.annotation.AnnotationConfigurationException: @AliasFor declaration on attribute 'responses' in annotation [com.capgemini.engineering.horus.common.controllers.HorusEndpoint] declares an alias for attribute 'value' in annotation [io.swagger.v3.oas.annotations.responses.ApiResponses] which is not meta-present.
I still tried to check if there was any difference in the annotation ApiResponses
from SpringBoot 3.0.0 to 3.0.1. However both use the version (swagger-annotations-jakarta, version 2.7.7). I Still tried change the springdoc-openapi-starter-webmvc-ui version from 2.0.2 to 2.0.0, but I got the same message.
I google for this kind of message and I found this: Spring aliasFor for Annotations with Target(PARAMETER) . However, I am not sure if the presented solution applies to my case. They use a HandlerMethodArgumentResolver
that, if I understtod correctly, works for annotations which target is ElementType.PARAMETER
while my annotation is ElementType.METHOD
. I took a look at org.springframework.web.method.support
package (that is where HandlerMethodArgumentResolver
is located) and I didn't find anything that could fit what I needed. i.e. an handler for methods, instead for parameters for these methods.
May be this can be a bug? why this error after a small version change?
Thanks,
Rafael Afonso