diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java index 9b6a0619a1a..0663b9e6057 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -142,7 +142,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe /** * Initialize this instance. */ - void init(ApplicationContext applicationContext, EventExpressionEvaluator evaluator) { + void init(ApplicationContext applicationContext, @Nullable EventExpressionEvaluator evaluator) { this.applicationContext = applicationContext; this.evaluator = evaluator; } diff --git a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java index 07cedeee7a1..ad89b9e5676 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -40,6 +40,7 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.MethodIntrospector; +import org.springframework.core.SpringProperties; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; @@ -56,6 +57,7 @@ import org.springframework.util.CollectionUtils; * * @author Stephane Nicoll * @author Juergen Hoeller + * @author Sebastien Deleuze * @since 4.2 * @see EventListenerFactory * @see DefaultEventListenerFactory @@ -63,6 +65,14 @@ import org.springframework.util.CollectionUtils; public class EventListenerMethodProcessor implements SmartInitializingSingleton, ApplicationContextAware, BeanFactoryPostProcessor { + /** + * Boolean flag controlled by a {@code spring.spel.ignore} system property that instructs Spring to + * ignore SpEL, i.e. to not initialize the SpEL infrastructure. + *
The default is "false".
+ */
+ private static final boolean shouldIgnoreSpel = SpringProperties.getFlag("spring.spel.ignore");
+
+
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
@@ -74,11 +84,21 @@ public class EventListenerMethodProcessor
@Nullable
private List The default is "false".
+ */
+ private static final boolean shouldIgnoreSpel = SpringProperties.getFlag("spring.spel.ignore");
+
static {
// Eagerly load the ContextClosedEvent class to avoid weird classloader issues
@@ -647,7 +656,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
// Tell the internal bean factory to use the context's class loader etc.
beanFactory.setBeanClassLoader(getClassLoader());
- beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver(beanFactory.getBeanClassLoader()));
+ if (!shouldIgnoreSpel) {
+ beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver(beanFactory.getBeanClassLoader()));
+ }
beanFactory.addPropertyEditorRegistrar(new ResourceEditorRegistrar(this, getEnvironment()));
// Configure the bean factory with context callbacks.