forked from spring-attic/spring-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes spring-atticgh-72
- Loading branch information
Showing
9 changed files
with
159 additions
and
28 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
18 changes: 18 additions & 0 deletions
18
...l-native-samples/jafu-webmvc/src/main/java/com/example/jafu/Target_SpringApplication.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,18 @@ | ||
package com.example.jafu; | ||
|
||
|
||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.support.ServletWebServerApplicationContextWithoutSpel; | ||
|
||
@TargetClass(className = "org.springframework.boot.SpringApplication") | ||
public final class Target_SpringApplication { | ||
|
||
// Use the application context without SpEL and avoid reflection | ||
@Substitute | ||
protected ConfigurableApplicationContext createApplicationContext() { | ||
return new ServletWebServerApplicationContextWithoutSpel(); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...ng-graal-native-samples/jafu/src/main/java/com/example/jafu/Target_SpringApplication.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,18 @@ | ||
package com.example.jafu; | ||
|
||
|
||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.support.GenericApplicationContextWithoutSpel; | ||
|
||
@TargetClass(className = "org.springframework.boot.SpringApplication") | ||
public final class Target_SpringApplication { | ||
|
||
// Use the application context without SpEL and avoid reflection | ||
@Substitute | ||
protected ConfigurableApplicationContext createApplicationContext() { | ||
return new GenericApplicationContextWithoutSpel(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...c/main/java/org/springframework/context/support/GenericApplicationContextWithoutSpel.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,55 @@ | ||
package org.springframework.context.support; | ||
|
||
import org.springframework.beans.factory.BeanFactory; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.beans.support.ResourceEditorRegistrar; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.ApplicationEventPublisherAware; | ||
import org.springframework.context.EmbeddedValueResolverAware; | ||
import org.springframework.context.EnvironmentAware; | ||
import org.springframework.context.MessageSourceAware; | ||
import org.springframework.context.ResourceLoaderAware; | ||
import org.springframework.core.io.ResourceLoader; | ||
|
||
// Skip StandardBeanExpressionResolver and LoadTimeWeaver | ||
public class GenericApplicationContextWithoutSpel extends GenericApplicationContext { | ||
|
||
@Override | ||
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { | ||
// Tell the internal bean factory to use the context's class loader etc. | ||
beanFactory.setBeanClassLoader(getClassLoader()); | ||
beanFactory.addPropertyEditorRegistrar(new ResourceEditorRegistrar(this, getEnvironment())); | ||
|
||
// Configure the bean factory with context callbacks. | ||
beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this)); | ||
beanFactory.ignoreDependencyInterface(EnvironmentAware.class); | ||
beanFactory.ignoreDependencyInterface(EmbeddedValueResolverAware.class); | ||
beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class); | ||
beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class); | ||
beanFactory.ignoreDependencyInterface(MessageSourceAware.class); | ||
beanFactory.ignoreDependencyInterface(ApplicationContextAware.class); | ||
|
||
// BeanFactory interface not registered as resolvable type in a plain factory. | ||
// MessageSource registered (and found for autowiring) as a bean. | ||
beanFactory.registerResolvableDependency(BeanFactory.class, beanFactory); | ||
beanFactory.registerResolvableDependency(ResourceLoader.class, this); | ||
beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this); | ||
beanFactory.registerResolvableDependency(ApplicationContext.class, this); | ||
|
||
// Register early post-processor for detecting inner beans as ApplicationListeners. | ||
beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(this)); | ||
|
||
// Register default environment beans. | ||
if (!beanFactory.containsLocalBean(ENVIRONMENT_BEAN_NAME)) { | ||
beanFactory.registerSingleton(ENVIRONMENT_BEAN_NAME, getEnvironment()); | ||
} | ||
if (!beanFactory.containsLocalBean(SYSTEM_PROPERTIES_BEAN_NAME)) { | ||
beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, getEnvironment().getSystemProperties()); | ||
} | ||
if (!beanFactory.containsLocalBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) { | ||
beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, getEnvironment().getSystemEnvironment()); | ||
} | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
...ng-graal-native-samples/jafu/src/main/resources/META-INF/native-image/reflect-config.json
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...ative-substitutions/src/main/java/org/springframework/internal/svm/RemoveSpelSupport.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,12 @@ | ||
package org.springframework.internal.svm; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
public class RemoveSpelSupport implements BooleanSupplier { | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return Boolean.valueOf(System.getProperty("spring.graal.remove-spel-support", "false")); | ||
} | ||
|
||
} |