Reflections reflections = new Reflections("my.project.prefix"); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Controller.class); for (Class<?> controller : annotated) { RequestMapping request = controller.getAnnotation(RequestMapping.class); String mapping = request.name(); }
/** * Create a {@link RequestMappingInfo} from the supplied * {@link RequestMapping @RequestMapping} annotation, which is either * a directly declared annotation, a meta-annotation, or the synthesized * result of merging annotation attributes within an annotation hierarchy. */ protected RequestMappingInfo createRequestMappingInfo( RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) { RequestMappingInfo.Builder builder = RequestMappingInfo .paths(resolveEmbeddedValuesInPatterns(requestMapping.path())) .methods(requestMapping.method()) .params(requestMapping.params()) .headers(requestMapping.headers()) .consumes(requestMapping.consumes()) .produces(requestMapping.produces()) .mappingName(requestMapping.name()); if (customCondition != null) { builder.customCondition(customCondition); } return builder.options(this.config).build(); }
/** * Create a {@link RequestMappingInfo} from the supplied * {@link RequestMapping @RequestMapping} annotation, which is either * a directly declared annotation, a meta-annotation, or the synthesized * result of merging annotation attributes within an annotation hierarchy. */ protected RequestMappingInfo createRequestMappingInfo( RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) { RequestMappingInfo.Builder builder = RequestMappingInfo .paths(resolveEmbeddedValuesInPatterns(requestMapping.path())) .methods(requestMapping.method()) .params(requestMapping.params()) .headers(requestMapping.headers()) .consumes(requestMapping.consumes()) .produces(requestMapping.produces()) .mappingName(requestMapping.name()); if (customCondition != null) { builder.customCondition(customCondition); } return builder.options(this.config).build(); }
/** * Create a {@link RequestMappingInfo} from the supplied * {@link RequestMapping @RequestMapping} annotation, which is either * a directly declared annotation, a meta-annotation, or the synthesized * result of merging annotation attributes within an annotation hierarchy. */ protected RequestMappingInfo createRequestMappingInfo( RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) { RequestMappingInfo.Builder builder = RequestMappingInfo .paths(resolveEmbeddedValuesInPatterns(requestMapping.path())) .methods(requestMapping.method()) .params(requestMapping.params()) .headers(requestMapping.headers()) .consumes(requestMapping.consumes()) .produces(requestMapping.produces()) .mappingName(requestMapping.name()); if (customCondition != null) { builder.customCondition(customCondition); } return builder.options(this.config).build(); }
RequestMapping reqMapping = TestController.class.getAnnotation(RequestMapping.class); String name = reqMapping.name(); //now name shoud have value as "/blog/"
public String getName() { RequestMapping requestMapping = method.getAnnotation(RequestMapping.class); if (requestMapping != null) { return requestMapping.name(); } GetMapping getMapping = method.getAnnotation(GetMapping.class); if (getMapping != null) { return getMapping.name(); } PostMapping postMapping = method.getAnnotation(PostMapping.class); if (postMapping != null) { return postMapping.name(); } PutMapping putMapping = method.getAnnotation(PutMapping.class); if (putMapping != null) { return putMapping.name(); } PatchMapping patchMapping = method.getAnnotation(PatchMapping.class); if (patchMapping != null) { return patchMapping.name(); } DeleteMapping deleteMapping = method.getAnnotation(DeleteMapping.class); if (deleteMapping != null) { return deleteMapping.name(); } return null; }
private SwaggerMethod createSwaggerMethod(RequestMapping methodRequestMapping, Method method) { SwaggerMethod swaggerMethod = new SwaggerMethod(); swaggerMethod.setOperationId(method.getName()); swaggerMethod.setDescription(methodRequestMapping.name()); swaggerMethod.setConsumes(methodRequestMapping.consumes()); swaggerMethod.setProduces(methodRequestMapping.produces()); swaggerMethod.setParameters(createSwaggerParameterArray(method)); swaggerMethod.getTags().add(serviceClass.getSimpleName()); SwaggerResponse responseOk = new SwaggerResponse(); responseOk.setDescription("Unknown Description"); swaggerMethod.getResponses().put("200", responseOk); return swaggerMethod; }
/** * Create a {@link RequestMappingInfo} from the supplied * {@link RequestMapping @RequestMapping} annotation, which is either * a directly declared annotation, a meta-annotation, or the synthesized * result of merging annotation attributes within an annotation hierarchy. */ protected RequestMappingInfo createRequestMappingInfo( RequestMapping requestMapping, RequestCondition<?> customCondition) { return RequestMappingInfo .paths(resolveEmbeddedValuesInPatterns(requestMapping.path())) .methods(requestMapping.method()) .params(requestMapping.params()) .headers(requestMapping.headers()) .consumes(requestMapping.consumes()) .produces(requestMapping.produces()) .mappingName(requestMapping.name()) .customCondition(customCondition) .options(this.config) .build(); }
config.addAllowedMethod(allowedMethod.name());