Use NativeDetector.inNativeImage() instead of manual property check.
Closes: #2298 Original pull request: #2299. Relates to: spring-projects/spring-framework#25795
This commit is contained in:
committed by
Mark Paluch
parent
b51bee7a0b
commit
67ee745374
@@ -38,6 +38,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.core.NativeDetector;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -86,8 +87,6 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
|
||||
implements MappingContext<E, P>, ApplicationEventPublisherAware, ApplicationContextAware, InitializingBean {
|
||||
|
||||
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
|
||||
|
||||
private final Optional<E> NONE = Optional.empty();
|
||||
private final Map<TypeInformation<?>, Optional<E>> persistentEntities = new HashMap<>();
|
||||
private final PersistentPropertyAccessorFactory persistentPropertyAccessorFactory;
|
||||
@@ -109,7 +108,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
|
||||
|
||||
EntityInstantiators instantiators = new EntityInstantiators();
|
||||
PersistentPropertyAccessorFactory accessorFactory = IN_NATIVE_IMAGE ? BeanWrapperPropertyAccessorFactory.INSTANCE
|
||||
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage() ? BeanWrapperPropertyAccessorFactory.INSTANCE
|
||||
: new ClassGeneratingPropertyAccessorFactory();
|
||||
|
||||
this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory,
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.asm.Opcodes;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.cglib.core.ReflectUtils;
|
||||
import org.springframework.core.NativeDetector;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
@@ -55,7 +56,6 @@ import org.springframework.util.ClassUtils;
|
||||
class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(ClassGeneratingEntityInstantiator.class);
|
||||
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
|
||||
|
||||
private static final Object[] EMPTY_ARGS = new Object[0];
|
||||
|
||||
@@ -142,7 +142,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
*/
|
||||
boolean shouldUseReflectionEntityInstantiator(PersistentEntity<?, ?> entity) {
|
||||
|
||||
if (IN_NATIVE_IMAGE) {
|
||||
if (NativeDetector.inNativeImage()) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("graalvm.nativeimage - fall back to reflection for %s.", entity.getName()));
|
||||
|
||||
Reference in New Issue
Block a user