Merge branch '5.3.x'
# Conflicts: # spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
This commit is contained in:
commit
4d7fa9a632
|
|
@ -130,6 +130,10 @@ import org.springframework.util.StringValueResolver;
|
|||
public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBeanPostProcessor
|
||||
implements InstantiationAwareBeanPostProcessor, BeanFactoryAware, Serializable {
|
||||
|
||||
// Defensive reference to JNDI API for JDK 9+ (optional java.naming module)
|
||||
private static final boolean jndiPresent = ClassUtils.isPresent(
|
||||
"javax.naming.InitialContext", CommonAnnotationBeanPostProcessor.class.getClassLoader());
|
||||
|
||||
private static final Set<Class<? extends Annotation>> resourceAnnotationTypes = new LinkedHashSet<>(4);
|
||||
|
||||
@Nullable
|
||||
|
|
@ -151,7 +155,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
|||
|
||||
private boolean alwaysUseJndiLookup = false;
|
||||
|
||||
private transient BeanFactory jndiFactory = new SimpleJndiBeanFactory();
|
||||
@Nullable
|
||||
private transient BeanFactory jndiFactory;
|
||||
|
||||
@Nullable
|
||||
private transient BeanFactory resourceFactory;
|
||||
|
|
@ -175,6 +180,11 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
|||
setOrder(Ordered.LOWEST_PRECEDENCE - 3);
|
||||
setInitAnnotationType(PostConstruct.class);
|
||||
setDestroyAnnotationType(PreDestroy.class);
|
||||
|
||||
// java.naming module present on JDK 9+?
|
||||
if (jndiPresent) {
|
||||
this.jndiFactory = new SimpleJndiBeanFactory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -421,6 +431,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
|||
public void releaseTarget(Object target) {
|
||||
}
|
||||
};
|
||||
|
||||
ProxyFactory pf = new ProxyFactory();
|
||||
pf.setTargetSource(ts);
|
||||
if (element.lookupType.isInterface()) {
|
||||
|
|
@ -441,12 +452,23 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
|||
protected Object getResource(LookupElement element, @Nullable String requestingBeanName)
|
||||
throws NoSuchBeanDefinitionException {
|
||||
|
||||
// JNDI lookup to perform?
|
||||
String jndiName = null;
|
||||
if (StringUtils.hasLength(element.mappedName)) {
|
||||
return this.jndiFactory.getBean(element.mappedName, element.lookupType);
|
||||
jndiName = element.mappedName;
|
||||
}
|
||||
if (this.alwaysUseJndiLookup) {
|
||||
return this.jndiFactory.getBean(element.name, element.lookupType);
|
||||
else if (this.alwaysUseJndiLookup) {
|
||||
jndiName = element.name;
|
||||
}
|
||||
if (jndiName != null) {
|
||||
if (this.jndiFactory == null) {
|
||||
throw new NoSuchBeanDefinitionException(element.lookupType,
|
||||
"No JNDI factory configured - specify the 'jndiFactory' property");
|
||||
}
|
||||
return this.jndiFactory.getBean(jndiName, element.lookupType);
|
||||
}
|
||||
|
||||
// Regular resource autowiring
|
||||
if (this.resourceFactory == null) {
|
||||
throw new NoSuchBeanDefinitionException(element.lookupType,
|
||||
"No resource factory configured - specify the 'resourceFactory' property");
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import org.springframework.util.StringUtils;
|
|||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Phillip Webb
|
||||
* @since 3.1
|
||||
* @see ConfigurableEnvironment
|
||||
* @see StandardEnvironment
|
||||
|
|
@ -127,6 +128,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
|||
* {@link #customizePropertySources(MutablePropertySources)} during
|
||||
* construction to allow subclasses to contribute or manipulate
|
||||
* {@link PropertySource} instances as appropriate.
|
||||
* @param propertySources property sources to use
|
||||
* @since 5.3.4
|
||||
* @see #customizePropertySources(MutablePropertySources)
|
||||
*/
|
||||
|
|
@ -136,6 +138,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
|||
customizePropertySources(propertySources);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method used to create the {@link ConfigurablePropertyResolver}
|
||||
* instance used by the Environment.
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ package org.springframework.core.env;
|
|||
* variable names.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Phillip Webb
|
||||
* @since 3.1
|
||||
* @see ConfigurableEnvironment
|
||||
* @see SystemEnvironmentPropertySource
|
||||
|
|
@ -61,13 +62,15 @@ public class StandardEnvironment extends AbstractEnvironment {
|
|||
|
||||
|
||||
/**
|
||||
* Create a new {@code StandardEnvironment} instance.
|
||||
* Create a new {@code StandardEnvironment} instance with a default
|
||||
* {@link MutablePropertySources} instance.
|
||||
*/
|
||||
public StandardEnvironment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code StandardEnvironment} instance with a specific {@link MutablePropertySources} instance.
|
||||
* Create a new {@code StandardEnvironment} instance with a specific
|
||||
* {@link MutablePropertySources} instance.
|
||||
* @param propertySources property sources to use
|
||||
* @since 5.3.4
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
|
|
@ -278,7 +278,7 @@ final class LogAdapter {
|
|||
|
||||
protected final String name;
|
||||
|
||||
protected transient T logger;
|
||||
protected final transient T logger;
|
||||
|
||||
public Slf4jLog(T logger) {
|
||||
this.name = logger.getName();
|
||||
|
|
@ -500,9 +500,9 @@ final class LogAdapter {
|
|||
@SuppressWarnings("serial")
|
||||
private static class JavaUtilLog implements Log, Serializable {
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
private transient java.util.logging.Logger logger;
|
||||
private final transient java.util.logging.Logger logger;
|
||||
|
||||
public JavaUtilLog(String name) {
|
||||
this.name = name;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.springframework.core.env.StandardEnvironment;
|
|||
import org.springframework.jndi.JndiLocatorDelegate;
|
||||
import org.springframework.jndi.JndiPropertySource;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.context.ConfigurableWebEnvironment;
|
||||
|
||||
/**
|
||||
|
|
@ -39,6 +40,7 @@ import org.springframework.web.context.ConfigurableWebEnvironment;
|
|||
* documentation for details.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @see StandardEnvironment
|
||||
*/
|
||||
|
|
@ -54,6 +56,11 @@ public class StandardServletEnvironment extends StandardEnvironment implements C
|
|||
public static final String JNDI_PROPERTY_SOURCE_NAME = "jndiProperties";
|
||||
|
||||
|
||||
// Defensive reference to JNDI API for JDK 9+ (optional java.naming module)
|
||||
private static final boolean jndiPresent = ClassUtils.isPresent(
|
||||
"javax.naming.InitialContext", StandardServletEnvironment.class.getClassLoader());
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code StandardServletEnvironment} instance.
|
||||
*/
|
||||
|
|
@ -100,7 +107,7 @@ public class StandardServletEnvironment extends StandardEnvironment implements C
|
|||
protected void customizePropertySources(MutablePropertySources propertySources) {
|
||||
propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
|
||||
propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
|
||||
if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
|
||||
if (jndiPresent && JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
|
||||
propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
|
||||
}
|
||||
super.customizePropertySources(propertySources);
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@
|
|||
<property name="headerCopyrightPattern" value="20\d\d-20\d\d"/>
|
||||
<property name="packageInfoHeaderType" value="none"/>
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck">
|
||||
<property name="lineSeparator" value="lf"/>
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
|
||||
|
||||
<!-- TreeWalker Checks -->
|
||||
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
|
||||
|
|
|
|||
Loading…
Reference in New Issue