|
25 | 25 | import org.jboss.jandex.IndexView; |
26 | 26 | import org.jboss.jandex.MethodInfo; |
27 | 27 | import org.jboss.jandex.Type; |
| 28 | +import org.jboss.logging.Logger; |
28 | 29 | import org.jboss.resteasy.core.MediaTypeMap; |
29 | 30 | import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters; |
30 | 31 | import org.jboss.resteasy.spi.ResteasyDeployment; |
|
63 | 64 |
|
64 | 65 | public class SpringWebProcessor { |
65 | 66 |
|
| 67 | + private static final Logger LOGGER = Logger.getLogger(SpringWebProcessor.class.getName()); |
| 68 | + |
66 | 69 | private static final DotName REST_CONTROLLER_ANNOTATION = DotName |
67 | 70 | .createSimple("org.springframework.web.bind.annotation.RestController"); |
68 | 71 |
|
@@ -162,6 +165,8 @@ public void process(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem, |
162 | 165 | BuildProducer<ServletInitParamBuildItem> initParamProducer, |
163 | 166 | BuildProducer<ResteasyDeploymentCustomizerBuildItem> deploymentCustomizerProducer) { |
164 | 167 |
|
| 168 | + validateControllers(beanArchiveIndexBuildItem); |
| 169 | + |
165 | 170 | final IndexView index = beanArchiveIndexBuildItem.getIndex(); |
166 | 171 | final Collection<AnnotationInstance> annotations = index.getAnnotations(REST_CONTROLLER_ANNOTATION); |
167 | 172 | if (annotations.isEmpty()) { |
@@ -190,6 +195,35 @@ public void accept(ResteasyDeployment resteasyDeployment) { |
190 | 195 | reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, false, SpringResourceBuilder.class.getName())); |
191 | 196 | } |
192 | 197 |
|
| 198 | + /** |
| 199 | + * Make sure the controllers have the proper annotation and warn if not |
| 200 | + */ |
| 201 | + private void validateControllers(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem) { |
| 202 | + Collection<AnnotationInstance> annotations = beanArchiveIndexBuildItem.getIndex().getAnnotations(REQUEST_MAPPING); |
| 203 | + Set<DotName> classesWithoutRestController = new HashSet<>(); |
| 204 | + for (AnnotationInstance annotation : annotations) { |
| 205 | + ClassInfo targetClass; |
| 206 | + if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) { |
| 207 | + targetClass = annotation.target().asClass(); |
| 208 | + } else if (annotation.target().kind() == AnnotationTarget.Kind.METHOD) { |
| 209 | + targetClass = annotation.target().asMethod().declaringClass(); |
| 210 | + } else { |
| 211 | + continue; |
| 212 | + } |
| 213 | + |
| 214 | + if (targetClass.classAnnotation(REST_CONTROLLER_ANNOTATION) == null) { |
| 215 | + classesWithoutRestController.add(targetClass.name()); |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + if (!classesWithoutRestController.isEmpty()) { |
| 220 | + for (DotName dotName : classesWithoutRestController) { |
| 221 | + LOGGER.warn("Class '" + dotName |
| 222 | + + "' uses '@RequestMapping' but was not annotated with '@RestContoller' and will therefore be ignored."); |
| 223 | + } |
| 224 | + } |
| 225 | + } |
| 226 | + |
193 | 227 | @BuildStep(onlyIf = IsDevelopment.class) |
194 | 228 | @Record(STATIC_INIT) |
195 | 229 | public void registerWithDevModeNotFoundMapper(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem, |
|
0 commit comments