forked from spring-projects/spring-framework
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base infra for Web controllers hints
- Loading branch information
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
spring-web/src/main/java/org/springframework/http/MediaTypeResourceHintsRegistrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../main/java/org/springframework/web/bind/annotation/RequestMappingReflectiveProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ain/java/org/springframework/web/bind/annotation/WebAnnotationsRuntimeHintsRegistrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/native-image/org.springframework/spring-web/native-image.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Args = --initialize-at-build-time=org.springframework.http.HttpStatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.springframework.aot.hint.RuntimeHintsRegistrar= \ | ||
org.springframework.http.MediaTypeResourceHintsRegistrar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters