Add base infra for Web controllers hints
See gh-28518
This commit is contained in:
committed by
Sébastien Deleuze
parent
472af9c25f
commit
0992f855e6
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link RuntimeHintsRegistrar} implementation that makes sure mime types
|
||||
* are available in constrained environments.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 6.0
|
||||
*/
|
||||
class MediaTypeResourceHintsRegistrar implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
hints.resources().registerPattern("org/springframework/http/mime.types");
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.aot.hint.annotation.Reflective;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
@@ -72,6 +73,7 @@ import org.springframework.core.annotation.AliasFor;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Mapping
|
||||
@Reflective(RequestMappingReflectiveProcessor.class)
|
||||
public @interface RequestMapping {
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.bind.annotation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.aot.hint.ReflectionHints;
|
||||
import org.springframework.aot.hint.annotation.ReflectiveProcessor;
|
||||
import org.springframework.aot.hint.annotation.SimpleReflectiveProcessor;
|
||||
|
||||
/**
|
||||
* {@link ReflectiveProcessor} implementation for {@link RequestMapping}
|
||||
* annotated types. On top of registering reflection hints for invoking
|
||||
* the annotated method, this implementation handles return types that
|
||||
* are serialized as well as TBD.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 6.0
|
||||
*/
|
||||
class RequestMappingReflectiveProcessor extends SimpleReflectiveProcessor {
|
||||
|
||||
@Override
|
||||
protected void registerMethodHint(ReflectionHints hints, Method method) {
|
||||
super.registerMethodHint(hints, method);
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.bind.annotation;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.support.RuntimeHintsUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* {@link RuntimeHintsRegistrar} implementation that make web binding
|
||||
* annotations at runtime.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 6.0
|
||||
*/
|
||||
public final class WebAnnotationsRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
Stream.of(Controller.class, ControllerAdvice.class, CookieValue.class,
|
||||
CrossOrigin.class, DeleteMapping.class, ExceptionHandler.class,
|
||||
GetMapping.class, InitBinder.class, Mapping.class, MatrixVariable.class,
|
||||
ModelAttribute.class, PatchMapping.class, PathVariable.class,
|
||||
PostMapping.class, PutMapping.class, RequestAttribute.class,
|
||||
RequestBody.class, RequestHeader.class, RequestMapping.class,
|
||||
RequestParam.class, RequestPart.class, ResponseBody.class,
|
||||
ResponseStatus.class, RestController.class, RestControllerAdvice.class,
|
||||
SessionAttribute.class, SessionAttributes.class).forEach(
|
||||
annotationType -> RuntimeHintsUtils.registerAnnotation(hints, annotationType));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user