Java源码示例:org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping
示例1
/**
* An alternative to {@link #fromMappingName(String)} that accepts a
* {@code UriComponentsBuilder} representing the base URL. This is useful
* when using MvcUriComponentsBuilder outside the context of processing a
* request or to apply a custom baseUrl not matching the current request.
* <p><strong>Note:</strong> This method extracts values from "Forwarded"
* and "X-Forwarded-*" headers if found. See class-level docs.
* @param builder the builder for the base URL; the builder will be cloned
* and therefore not modified and may be re-used for further calls.
* @param name the mapping name
* @return a builder to prepare the URI String
* @throws IllegalArgumentException if the mapping name is not found or
* if there is no unique match
* @since 4.2
*/
public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuilder builder, String name) {
WebApplicationContext wac = getWebApplicationContext();
Assert.notNull(wac, "No WebApplicationContext. ");
Map<String, RequestMappingInfoHandlerMapping> map = wac.getBeansOfType(RequestMappingInfoHandlerMapping.class);
List<HandlerMethod> handlerMethods = null;
for (RequestMappingInfoHandlerMapping mapping : map.values()) {
handlerMethods = mapping.getHandlerMethodsForMappingName(name);
if (handlerMethods != null) {
break;
}
}
if (handlerMethods == null) {
throw new IllegalArgumentException("Mapping not found: " + name);
}
else if (handlerMethods.size() != 1) {
throw new IllegalArgumentException("No unique match for mapping " + name + ": " + handlerMethods);
}
else {
HandlerMethod handlerMethod = handlerMethods.get(0);
Class<?> controllerType = handlerMethod.getBeanType();
Method method = handlerMethod.getMethod();
return new MethodArgumentBuilder(builder, controllerType, method);
}
}
示例2
/**
* Instantiates a new Open api resource.
*
* @param openAPIBuilderObjectFactory the open api builder object factory
* @param requestBuilder the request builder
* @param responseBuilder the response builder
* @param operationParser the operation parser
* @param requestMappingHandlerMapping the request mapping handler mapping
* @param actuatorProvider the actuator provider
* @param operationCustomizers the operation customizers
* @param openApiCustomisers the open api customisers
* @param springDocConfigProperties the spring doc config properties
* @param springSecurityOAuth2Provider the spring security o auth 2 provider
* @param routerFunctionProvider the router function provider
* @param repositoryRestResourceProvider the repository rest resource provider
*/
@Autowired
public OpenApiResource(ObjectFactory<OpenAPIBuilder> openAPIBuilderObjectFactory, AbstractRequestBuilder requestBuilder,
GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
Optional<ActuatorProvider> actuatorProvider,
Optional<List<OperationCustomizer>> operationCustomizers,
Optional<List<OpenApiCustomiser>> openApiCustomisers,
SpringDocConfigProperties springDocConfigProperties,
Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
Optional<RouterFunctionProvider> routerFunctionProvider,
Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
super(DEFAULT_GROUP_NAME, openAPIBuilderObjectFactory, requestBuilder, responseBuilder, operationParser, operationCustomizers, openApiCustomisers, springDocConfigProperties,actuatorProvider);
this.requestMappingHandlerMapping = requestMappingHandlerMapping;
this.springSecurityOAuth2Provider = springSecurityOAuth2Provider;
this.routerFunctionProvider = routerFunctionProvider;
this.repositoryRestResourceProvider = repositoryRestResourceProvider;
}
示例3
/**
* Instantiates a new Multiple open api resource.
*
* @param groupedOpenApis the grouped open apis
* @param defaultOpenAPIBuilder the default open api builder
* @param requestBuilder the request builder
* @param responseBuilder the response builder
* @param operationParser the operation parser
* @param requestMappingHandlerMapping the request mapping handler mapping
* @param actuatorProvider the actuator provider
* @param springDocConfigProperties the spring doc config properties
* @param springSecurityOAuth2Provider the spring security o auth 2 provider
* @param routerFunctionProvider the router function provider
* @param repositoryRestResourceProvider the repository rest resource provider
*/
public MultipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
RequestMappingInfoHandlerMapping requestMappingHandlerMapping, Optional<ActuatorProvider> actuatorProvider,
SpringDocConfigProperties springDocConfigProperties, Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
Optional<RouterFunctionProvider> routerFunctionProvider,
Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
this.groupedOpenApis = groupedOpenApis;
this.defaultOpenAPIBuilder = defaultOpenAPIBuilder;
this.requestBuilder = requestBuilder;
this.responseBuilder = responseBuilder;
this.operationParser = operationParser;
this.requestMappingHandlerMapping = requestMappingHandlerMapping;
this.actuatorProvider = actuatorProvider;
this.springDocConfigProperties = springDocConfigProperties;
this.springSecurityOAuth2Provider = springSecurityOAuth2Provider;
this.routerFunctionProvider = routerFunctionProvider;
this.repositoryRestResourceProvider=repositoryRestResourceProvider;
}
示例4
/**
* Multiple open api resource multiple open api resource.
*
* @param groupedOpenApis the grouped open apis
* @param defaultOpenAPIBuilder the default open api builder
* @param requestBuilder the request builder
* @param responseBuilder the response builder
* @param operationParser the operation parser
* @param requestMappingHandlerMapping the request mapping handler mapping
* @param actuatorProvider the actuator provider
* @param springDocConfigProperties the spring doc config properties
* @param springSecurityOAuth2Provider the spring security o auth 2 provider
* @param routerFunctionProvider the router function provider
* @param repositoryRestResourceProvider the repository rest resource provider
* @return the multiple open api resource
*/
@Bean
@ConditionalOnMissingBean
@Lazy(false)
MultipleOpenApiResource multipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
Optional<ActuatorProvider> actuatorProvider,
SpringDocConfigProperties springDocConfigProperties,
Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
Optional<RouterFunctionProvider> routerFunctionProvider,
Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
return new MultipleOpenApiResource(groupedOpenApis,
defaultOpenAPIBuilder, requestBuilder,
responseBuilder, operationParser,
requestMappingHandlerMapping, actuatorProvider,
springDocConfigProperties,
springSecurityOAuth2Provider,
routerFunctionProvider,repositoryRestResourceProvider);
}
示例5
/**
* Open api resource open api resource.
*
* @param openAPIBuilderObjectFactory the open api builder object factory
* @param requestBuilder the request builder
* @param responseBuilder the response builder
* @param operationParser the operation parser
* @param requestMappingHandlerMapping the request mapping handler mapping
* @param actuatorProvider the actuator provider
* @param springDocConfigProperties the spring doc config properties
* @param operationCustomizers the operation customizers
* @param openApiCustomisers the open api customisers
* @param springSecurityOAuth2Provider the spring security o auth 2 provider
* @param routerFunctionProvider the router function provider
* @param repositoryRestResourceProvider the repository rest resource provider
* @return the open api resource
*/
@Bean
@ConditionalOnMissingBean
@Lazy(false)
OpenApiResource openApiResource(ObjectFactory<OpenAPIBuilder> openAPIBuilderObjectFactory, AbstractRequestBuilder requestBuilder,
GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
Optional<ActuatorProvider> actuatorProvider,
SpringDocConfigProperties springDocConfigProperties,
Optional<List<OperationCustomizer>> operationCustomizers,
Optional<List<OpenApiCustomiser>> openApiCustomisers,
Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
Optional<RouterFunctionProvider> routerFunctionProvider,
Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
return new OpenApiResource(openAPIBuilderObjectFactory, requestBuilder,
responseBuilder, operationParser,
requestMappingHandlerMapping, actuatorProvider, operationCustomizers,
openApiCustomisers, springDocConfigProperties, springSecurityOAuth2Provider,
routerFunctionProvider, repositoryRestResourceProvider);
}
示例6
/**
* An alternative to {@link #fromMappingName(String)} that accepts a
* {@code UriComponentsBuilder} representing the base URL. This is useful
* when using MvcUriComponentsBuilder outside the context of processing a
* request or to apply a custom baseUrl not matching the current request.
* <p><strong>Note:</strong> This method extracts values from "Forwarded"
* and "X-Forwarded-*" headers if found. See class-level docs.
* @param builder the builder for the base URL; the builder will be cloned
* and therefore not modified and may be re-used for further calls.
* @param name the mapping name
* @return a builder to prepare the URI String
* @throws IllegalArgumentException if the mapping name is not found or
* if there is no unique match
* @since 4.2
*/
public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuilder builder, String name) {
WebApplicationContext wac = getWebApplicationContext();
Assert.notNull(wac, "No WebApplicationContext. ");
Map<String, RequestMappingInfoHandlerMapping> map = wac.getBeansOfType(RequestMappingInfoHandlerMapping.class);
List<HandlerMethod> handlerMethods = null;
for (RequestMappingInfoHandlerMapping mapping : map.values()) {
handlerMethods = mapping.getHandlerMethodsForMappingName(name);
if (handlerMethods != null) {
break;
}
}
if (handlerMethods == null) {
throw new IllegalArgumentException("Mapping not found: " + name);
}
else if (handlerMethods.size() != 1) {
throw new IllegalArgumentException("No unique match for mapping " + name + ": " + handlerMethods);
}
else {
HandlerMethod handlerMethod = handlerMethods.get(0);
Class<?> controllerType = handlerMethod.getBeanType();
Method method = handlerMethod.getMethod();
return new MethodArgumentBuilder(builder, controllerType, method);
}
}
示例7
/**
* An alternative to {@link #fromMappingName(String)} that accepts a
* {@code UriComponentsBuilder} representing the base URL. This is useful
* when using MvcUriComponentsBuilder outside the context of processing a
* request or to apply a custom baseUrl not matching the current request.
* <p><strong>Note:</strong> This method extracts values from "Forwarded"
* and "X-Forwarded-*" headers if found. See class-level docs.
* @param builder the builder for the base URL; the builder will be cloned
* and therefore not modified and may be re-used for further calls.
* @param name the mapping name
* @return a builder to prepare the URI String
* @throws IllegalArgumentException if the mapping name is not found or
* if there is no unique match
* @since 4.2
*/
public static MethodArgumentBuilder fromMappingName(UriComponentsBuilder builder, String name) {
RequestMappingInfoHandlerMapping handlerMapping = getRequestMappingInfoHandlerMapping();
List<HandlerMethod> handlerMethods = handlerMapping.getHandlerMethodsForMappingName(name);
if (handlerMethods == null) {
throw new IllegalArgumentException("Mapping mappingName not found: " + name);
}
if (handlerMethods.size() != 1) {
throw new IllegalArgumentException("No unique match for mapping mappingName " +
name + ": " + handlerMethods);
}
HandlerMethod handlerMethod = handlerMethods.get(0);
Class<?> controllerType = handlerMethod.getBeanType();
Method method = handlerMethod.getMethod();
return new MethodArgumentBuilder(builder, controllerType, method);
}
示例8
/**
* An alternative to {@link #fromMappingName(String)} that accepts a
* {@code UriComponentsBuilder} representing the base URL. This is useful
* when using MvcUriComponentsBuilder outside the context of processing a
* request or to apply a custom baseUrl not matching the current request.
* @param builder the builder for the base URL; the builder will be cloned
* and therefore not modified and may be re-used for further calls.
* @param name the mapping name
* @return a builder to to prepare the URI String
* @throws IllegalArgumentException if the mapping name is not found or
* if there is no unique match
* @since 4.2
*/
public static MethodArgumentBuilder fromMappingName(UriComponentsBuilder builder, String name) {
RequestMappingInfoHandlerMapping handlerMapping = getRequestMappingInfoHandlerMapping();
List<HandlerMethod> handlerMethods = handlerMapping.getHandlerMethodsForMappingName(name);
if (handlerMethods == null) {
throw new IllegalArgumentException("Mapping mappingName not found: " + name);
}
if (handlerMethods.size() != 1) {
throw new IllegalArgumentException("No unique match for mapping mappingName " +
name + ": " + handlerMethods);
}
HandlerMethod handlerMethod = handlerMethods.get(0);
Class<?> controllerType = handlerMethod.getBeanType();
Method method = handlerMethod.getMethod();
return new MethodArgumentBuilder(builder, controllerType, method);
}
示例9
/**
* Instantiates a new Open api resource.
*
* @param groupName the group name
* @param openAPIBuilderObjectFactory the open api builder object factory
* @param requestBuilder the request builder
* @param responseBuilder the response builder
* @param operationParser the operation parser
* @param requestMappingHandlerMapping the request mapping handler mapping
* @param actuatorProvider the actuator provider
* @param operationCustomizers the operation customizers
* @param openApiCustomisers the open api customisers
* @param springDocConfigProperties the spring doc config properties
* @param springSecurityOAuth2Provider the spring security o auth 2 provider
* @param routerFunctionProvider the router function provider
* @param repositoryRestResourceProvider the repository rest resource provider
*/
public OpenApiResource(String groupName, ObjectFactory<OpenAPIBuilder> openAPIBuilderObjectFactory, AbstractRequestBuilder requestBuilder,
GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
Optional<ActuatorProvider> actuatorProvider,
Optional<List<OperationCustomizer>> operationCustomizers,
Optional<List<OpenApiCustomiser>> openApiCustomisers,
SpringDocConfigProperties springDocConfigProperties,
Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
Optional<RouterFunctionProvider> routerFunctionProvider,
Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
super(groupName, openAPIBuilderObjectFactory, requestBuilder, responseBuilder, operationParser, operationCustomizers, openApiCustomisers, springDocConfigProperties,actuatorProvider);
this.requestMappingHandlerMapping = requestMappingHandlerMapping;
this.springSecurityOAuth2Provider = springSecurityOAuth2Provider;
this.routerFunctionProvider = routerFunctionProvider;
this.repositoryRestResourceProvider = repositoryRestResourceProvider;
}