forked from spring-attic/spring-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces various optimizations that allow to significantly reduce Spring Boot applications footprint when compiled as native images. The first one is the capability to remove XML parsers (see related oracle/graal#2327 GraalVM issue) including those configured habitually by Spring. XML Parsers from Logback, Tomcat, Spring Boot, Spring Framework Core/WebMvc/WebFlux can be disabled via -Dspring.graal.remove-xml-support=true and is implemented via various substitutions. Notice for now FormHttpMessageConverter is used instead of AllEncompassingFormHttpMessageConverter due to oracle/graal#2458. It is now also possible to remove SpEL via -Dspring.graal.remove-spel-support=true and JMX via -Dspring.graal.remove-jmx-support=true. BackgroundPreinitializer are now disabled since they do not make sense with GraalVM native. spring-graal-feature is now added as a regular Maven dependency in order to make the new org.springframework.boot.NativePropertiesListener taken in account when the agent is used. Key samples and petclinic ones have been updated to take advantage of those optimizations. Spring Fu samples now also takes advantages of spring-projects-experimental/spring-fu#269 and those capabilities. In the long run, these "not so easy to maintain substitutions" could maybe be replaced by a new GraalVM capability that would monitor used classes by the JVM via an agent and pass this list to native-image compiler to remove those unused classes from the native image in order to load classes lazily like the JVM does. It would also have the advantage to not require an explicit option to enable those optimizations. Closes spring-atticgh-109
- Loading branch information
Showing
108 changed files
with
1,736 additions
and
755 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
...native-configuration/src/main/java/org/springframework/boot/NativePropertiesListener.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,17 @@ | ||
package org.springframework.boot; | ||
|
||
import java.util.Properties; | ||
|
||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.PropertiesPropertySource; | ||
|
||
public class NativePropertiesListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> { | ||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { | ||
ConfigurableEnvironment environment = event.getEnvironment(); | ||
Properties props = new Properties(); | ||
props.put("server.servlet.register-default-servlet", "false"); | ||
environment.getPropertySources().addFirst(new PropertiesPropertySource("myProps", props)); | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
...ration/src/main/java/org/springframework/boot/autoconfigure/web/reactive/netty/Hints.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,69 @@ | ||
/* | ||
* Copyright 2020 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 | ||
* | ||
* http://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.boot.autoconfigure.web.reactive.netty; | ||
|
||
import io.netty.channel.ChannelHandler; | ||
import io.netty.channel.ChannelHandlerAdapter; | ||
import io.netty.channel.ChannelInboundHandler; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import reactor.netty.DisposableServer; | ||
|
||
import org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration.BeanPostProcessorsRegistrar; | ||
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration; | ||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext; | ||
import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor; | ||
import org.springframework.graal.extension.NativeImageConfiguration; | ||
import org.springframework.graal.extension.NativeImageHint; | ||
import org.springframework.graal.extension.TypeInfo; | ||
import org.springframework.graal.type.AccessBits; | ||
import org.springframework.http.codec.ClientCodecConfigurer; | ||
import org.springframework.http.codec.ServerCodecConfigurer; | ||
import org.springframework.http.codec.support.DefaultClientCodecConfigurer; | ||
import org.springframework.http.codec.support.DefaultServerCodecConfigurer; | ||
import org.springframework.web.reactive.HandlerResult; | ||
|
||
@NativeImageHint(typeInfos = { | ||
@TypeInfo(types= {ChannelInboundHandlerAdapter.class,ChannelHandlerAdapter.class, | ||
ChannelHandler.class,ChannelInboundHandler.class}, | ||
typeNames = { | ||
"io.netty.channel.ChannelInitializer", | ||
"io.netty.channel.DefaultChannelPipeline$HeadContext", | ||
"io.netty.channel.DefaultChannelPipeline$TailContext", | ||
"reactor.netty.channel.BootstrapHandlers$BootstrapInitializerHandler", | ||
"io.netty.channel.ChannelDuplexHandler", | ||
"io.netty.channel.CombinedChannelDuplexHandler", | ||
"io.netty.channel.AbstractChannelHandlerContext", | ||
"io.netty.channel.ChannelHandlerContext", | ||
"io.netty.handler.codec.http.HttpServerCodec", | ||
"reactor.netty.channel.ChannelOperationsHandler", | ||
"reactor.netty.http.server.HttpTrafficHandler", | ||
"io.netty.channel.ChannelDuplexHandler", | ||
"io.netty.channel.ChannelFutureListener", | ||
"io.netty.channel.DefaultChannelPipeline", | ||
"io.netty.channel.ChannelPipeline", | ||
"io.netty.channel.ChannelInboundInvoker", | ||
"io.netty.channel.ChannelOutboundInvoker", | ||
"io.netty.channel.ChannelHandler", | ||
"io.netty.util.concurrent.GenericFutureListener", | ||
"io.netty.bootstrap.ServerBootstrap$1", | ||
"io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor", | ||
"java.lang.management.ManagementFactory", | ||
"java.lang.management.RuntimeMXBean"}, | ||
access=AccessBits.CLASS|AccessBits.DECLARED_CONSTRUCTORS|AccessBits.DECLARED_METHODS) | ||
}) | ||
public class Hints implements NativeImageConfiguration { | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
spring-graal-native-configuration/src/main/resources/META-INF/spring.factories
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 @@ | ||
org.springframework.context.ApplicationListener=org.springframework.boot.NativePropertiesListener |
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
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
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
Oops, something went wrong.