Skip to content
GitLab
Explore
Sign in
Register
Commits on Source
2
New upstream version 4.3.20
· cb53abe5
Emmanuel Bourg
authored
Oct 16, 2018
cb53abe5
New upstream version 4.3.21
· d2188a36
Emmanuel Bourg
authored
Jan 01, 2019
d2188a36
Show whitespace changes
Inline
Side-by-side
build.gradle
View file @
d2188a36
...
...
@@ -41,7 +41,7 @@ configure(allprojects) { project ->
ext
.
fileuploadVersion
=
"1.3.3"
ext
.
freemarkerVersion
=
"2.3.23"
ext
.
groovyVersion
=
"2.4.15"
ext
.
gsonVersion
=
"2.8.
2
"
ext
.
gsonVersion
=
"2.8.
5
"
ext
.
guavaVersion
=
"20.0"
ext
.
hamcrestVersion
=
"1.3"
ext
.
hibernate3Version
=
"3.6.10.Final"
...
...
@@ -50,9 +50,9 @@ configure(allprojects) { project ->
ext
.
hibval4Version
=
"4.3.2.Final"
ext
.
hibval5Version
=
"5.2.5.Final"
ext
.
hsqldbVersion
=
"2.3.4"
ext
.
httpasyncVersion
=
"4.1.
3
"
ext
.
httpclientVersion
=
"4.5.
5
"
ext
.
jackson2Version
=
"2.8.11.
2
"
ext
.
httpasyncVersion
=
"4.1.
4
"
ext
.
httpclientVersion
=
"4.5.
6
"
ext
.
jackson2Version
=
"2.8.11.
3
"
ext
.
jasperreportsVersion
=
"6.2.1"
// our tests fail with JR-internal NPEs against 6.2.2 and higher
ext
.
javamailVersion
=
"1.5.6"
ext
.
jettyVersion
=
"9.3.14.v20161028"
// as of 9.3.15, Jetty has hard Servlet 3.1 requirement
...
...
@@ -62,7 +62,7 @@ configure(allprojects) { project ->
ext
.
jtaVersion
=
"1.2"
ext
.
junitVersion
=
"4.12"
ext
.
log4jVersion
=
"1.2.17"
ext
.
nettyVersion
=
"4.1.
29
.Final"
ext
.
nettyVersion
=
"4.1.
31
.Final"
ext
.
okhttpVersion
=
"2.7.5"
ext
.
okhttp3Version
=
"3.8.1"
ext
.
openjpaVersion
=
"2.4.2"
...
...
@@ -71,11 +71,11 @@ configure(allprojects) { project ->
ext
.
romeVersion
=
"1.7.4"
ext
.
slf4jVersion
=
"1.7.25"
ext
.
snakeyamlVersion
=
"1.17"
ext
.
snifferVersion
=
"1.1
6
"
ext
.
snifferVersion
=
"1.1
7
"
ext
.
testngVersion
=
"6.9.10"
ext
.
tiles2Version
=
"2.2.2"
ext
.
tiles3Version
=
"3.0.
7
"
ext
.
tomcatVersion
=
"8.5.3
3
"
ext
.
tiles3Version
=
"3.0.
8
"
ext
.
tomcatVersion
=
"8.5.3
5
"
ext
.
tyrusVersion
=
"1.3.5"
// constrained by WebLogic 12.1.3 support
ext
.
undertowVersion
=
"1.3.33.Final"
ext
.
xmlunitVersion
=
"1.6"
...
...
@@ -289,10 +289,9 @@ project("spring-build-src") {
project
(
"spring-core"
)
{
description
=
"Spring Core"
// As of Spring 4.0.3, spring-core includes asm 5.x and repackages cglib 3.2, inlining
// both into the spring-core jar. cglib 3.2 itself depends on asm 5.x and is therefore
// further transformed by the JarJar task to depend on org.springframework.asm; this
// avoids including two different copies of asm unnecessarily.
// spring-core includes asm and repackages cglib, inlining both into the spring-core jar.
// cglib itself depends on asm and is therefore further transformed by the JarJar task to
// depend on org.springframework.asm; this avoids including two different copies of asm.
def
cglibVersion
=
"3.2.6"
def
objenesisVersion
=
"2.6"
...
...
gradle.properties
View file @
d2188a36
version
=
4.3.1
9
.RELEASE
version
=
4.3.
2
1.RELEASE
spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java
View file @
d2188a36
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -150,7 +150,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
// since those are only meant to apply to beans defined in the original factory.
for
(
Iterator
<
BeanPostProcessor
>
it
=
internalBeanFactory
.
getBeanPostProcessors
().
iterator
();
it
.
hasNext
();)
{
if
(
it
.
next
()
instanceof
AopInfrastructureBean
)
{
it
.
remove
();
it
.
remove
();
// effectively deprecated: use List.removeIf on Java 8+
}
}
...
...
spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java
View file @
d2188a36
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -43,8 +43,10 @@ import org.springframework.util.ObjectUtils;
* Decorator for a standard {@link BeanInfo} object, e.g. as created by
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register static
* and/or non-void returning setter methods. For example:
*
* <pre class="code">
* public class Bean {
*
* private Foo foo;
*
* public Foo getFoo() {
...
...
@@ -56,6 +58,7 @@ import org.springframework.util.ObjectUtils;
* return this;
* }
* }</pre>
*
* The standard JavaBeans {@code Introspector} will discover the {@code getFoo} read
* method, but will bypass the {@code #setFoo(Foo)} write method, because its non-void
* returning signature does not comply with the JavaBeans specification.
...
...
@@ -68,6 +71,7 @@ import org.springframework.util.ObjectUtils;
* indexed properties</a> are fully supported.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
* @see #ExtendedBeanInfo(BeanInfo)
* @see ExtendedBeanInfoFactory
...
...
spring-beans/src/main/java/org/springframework/beans/factory/Aware.java
View file @
d2188a36
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -17,21 +17,19 @@
package
org.springframework.beans.factory
;
/**
* Marker superinterface indicating that a bean is eligible to be
* notified by the Spring container of a particular framework object
* through a callback-style method. Actual method signature is
* determined by individual subinterfaces, but should typically
* consist of just one void-returning method that accepts a single
* argument.
* A marker superinterface indicating that a bean is eligible to be notified by the
* Spring container of a particular framework object through a callback-style method.
* The actual method signature is determined by individual subinterfaces but should
* typically consist of just one void-returning method that accepts a single argument.
*
* <p>Note that merely implementing {@link Aware} provides no default
*
functionality.
Rather, processing must be done explicitly, for example
*
in a
{@link org.springframework.beans.factory.config.BeanPostProcessor
BeanPostProcessor
}.
* <p>Note that merely implementing {@link Aware} provides no default
functionality.
* Rather, processing must be done explicitly, for example
in a
* {@link org.springframework.beans.factory.config.BeanPostProcessor}.
* Refer to {@link org.springframework.context.support.ApplicationContextAwareProcessor}
* and {@link org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory}
* for examples of processing {@code *Aware} interface callbacks.
* for an example of processing specific {@code *Aware} interface callbacks.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
*/
public
interface
Aware
{
...
...
spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java
View file @
d2188a36
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -243,7 +243,9 @@ public interface ListableBeanFactory extends BeanFactory {
/**
* Find all names of beans whose {@code Class} has the supplied {@link Annotation}
* type, without creating any bean instances yet.
* type, without creating corresponding bean instances yet.
* <p>Note that this method considers objects created by FactoryBeans, which means
* that FactoryBeans will get initialized in order to determine their object type.
* @param annotationType the type of annotation to look for
* @return the names of all matching beans
* @since 4.0
...
...
@@ -253,6 +255,8 @@ public interface ListableBeanFactory extends BeanFactory {
/**
* Find all beans whose {@code Class} has the supplied {@link Annotation} type,
* returning a Map of bean names with corresponding bean instances.
* <p>Note that this method considers objects created by FactoryBeans, which means
* that FactoryBeans will get initialized in order to determine their object type.
* @param annotationType the type of annotation to look for
* @return a Map with the matching beans, containing the bean names as
* keys and the corresponding bean instances as values
...
...
@@ -267,7 +271,7 @@ public interface ListableBeanFactory extends BeanFactory {
* found on the given class itself.
* @param beanName the name of the bean to look for annotations on
* @param annotationType the annotation class to look for
* @return the annotation of the given type if found, or {@code null}
* @return the annotation of the given type if found, or {@code null}
otherwise
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
* @since 3.0
*/
...
...
spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java
View file @
d2188a36
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -44,26 +44,25 @@ public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver
}
/**
* Build the BeanWiringInfo for the given Configurable annotation.
* Build the
{@link
BeanWiringInfo
}
for the given
{@link
Configurable
}
annotation.
* @param beanInstance the bean instance
* @param annotation the Configurable annotation found on the bean class
* @return the resolved BeanWiringInfo
*/
protected
BeanWiringInfo
buildWiringInfo
(
Object
beanInstance
,
Configurable
annotation
)
{
if
(!
Autowire
.
NO
.
equals
(
annotation
.
autowire
()))
{
// Autowiring by name or by type
return
new
BeanWiringInfo
(
annotation
.
autowire
().
value
(),
annotation
.
dependencyCheck
());
}
else
{
if
(!
""
.
equals
(
annotation
.
value
()))
{
// explicitly specified bean name
else
if
(!
""
.
equals
(
annotation
.
value
()))
{
// Explicitly specified bean name for bean definition to take property values from
return
new
BeanWiringInfo
(
annotation
.
value
(),
false
);
}
else
{
//
d
efault bean name
//
D
efault bean name
for bean definition to take property values from
return
new
BeanWiringInfo
(
getDefaultBeanName
(
beanInstance
),
true
);
}
}
}
/**
* Determine the default bean name for the specified bean instance.
...
...
spring-beans/src/main/java/org/springframework/beans/factory/annotation/Autowired.java
View file @
d2188a36
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -23,15 +23,22 @@ import java.lang.annotation.RetentionPolicy;
import
java.lang.annotation.Target
;
/**
* Marks a constructor, field, setter method or config method as to be autowired
* by Spring's dependency injection facilities.
* Marks a constructor, field, setter method or config method as to be autowired by
* Spring's dependency injection facilities. This is an alternative to the JSR-330
* {@link javax.inject.Inject} annotation, adding required-vs-optional semantics.
*
* <p>Only one constructor (at max) of any given bean class may carry this annotation,
* indicating the constructor to autowire when used as a Spring bean. Such a
* constructor does not have to be public.
* <p>Only one constructor (at max) of any given bean class may declare this annotation
* with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor
* to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors
* declare the annotation, they will be considered as candidates for autowiring.
* The constructor with the greatest number of dependencies that can be satisfied by
* matching beans in the Spring container will be chosen. If none of the candidates
* can be satisfied, then a standard default constructor (if present) will be used.
* If a class only declares a single constructor to begin with, it will always be used,
* even if not annotated. An annotated constructor does not have to be public.
*
* <p>Fields are injected right after construction of a bean, before any config
*
methods
are invoked. Such a config field does not have to be public.
* <p>Fields are injected right after construction of a bean, before any config
methods
* are invoked. Such a config field does not have to be public.
*
* <p>Config methods may have an arbitrary name and any number of arguments; each of
* those arguments will be autowired with a matching bean in the Spring container.
...
...
spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
View file @
d2188a36
...
...
@@ -74,15 +74,15 @@ import org.springframework.util.StringUtils;
* <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation,
* if available, as a direct alternative to Spring's own {@code @Autowired}.
*
* <p>Only one constructor (at max) of any given bean class may
carry this
*
annotation
with the 'required' parameter set to {@code true},
*
indicating <i>the</i> constructor
to autowire when used as a Spring bean.
*
If multiple <i>non-required</i> constructors carry the annotation, they
*
will be considered as candidates for autowiring. The constructor with
*
the greatest number of dependencies
th
at
can
be satisfied by matching
*
beans in the Spring container will be chosen. If none of the candidates
*
can be satisfied, then a default constructor (if present) will
be used
.
* An annotated constructor does not have to be public.
* <p>Only one constructor (at max) of any given bean class may
declare this annotation
* with the 'required' parameter set to {@code true},
indicating <i>the</i> constructor
* to autowire when used as a Spring bean.
If multiple <i>non-required</i> constructors
*
declare the annotation, they will be considered as candidates for autowiring.
*
The constructor with the greatest number of dependencies that can be satisfied by
*
matching beans in the Spring container will be chosen. If none of
th
e
can
didates
*
can be satisfied, then a standard default constructor (if present) will be used.
*
If a class only declares a single constructor to begin with, it will always
be used
,
*
even if not annotated.
An annotated constructor does not have to be public.
*
* <p>Fields are injected right after construction of a bean, before any
* config methods are invoked. Such a config field does not have to be public.
...
...
@@ -163,11 +163,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
/**
* Set the 'autowired' annotation type, to be used on constructors, fields,
* setter methods and arbitrary config methods.
* <p>The default autowired annotation type is the Spring-provided
*
{@link Autowired}
annotation, as well as {@link Value}.
* <p>The default autowired annotation type is the Spring-provided
{@link Autowired}
* annotation, as well as {@link Value}.
* <p>This setter property exists so that developers can provide their own
* (non-Spring-specific) annotation type to indicate that a member is
*
supposed
to be autowired.
* (non-Spring-specific) annotation type to indicate that a member is
supposed
* to be autowired.
*/
public
void
setAutowiredAnnotationType
(
Class
<?
extends
Annotation
>
autowiredAnnotationType
)
{
Assert
.
notNull
(
autowiredAnnotationType
,
"'autowiredAnnotationType' must not be null"
);
...
...
@@ -178,11 +178,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
/**
* Set the 'autowired' annotation types, to be used on constructors, fields,
* setter methods and arbitrary config methods.
* <p>The default autowired annotation type is the Spring-provided
*
{@link Autowired}
annotation, as well as {@link Value}.
* <p>The default autowired annotation type is the Spring-provided
{@link Autowired}
* annotation, as well as {@link Value}.
* <p>This setter property exists so that developers can provide their own
* (non-Spring-specific) annotation types to indicate that a member is
*
supposed
to be autowired.
* (non-Spring-specific) annotation types to indicate that a member is
supposed
* to be autowired.
*/
public
void
setAutowiredAnnotationTypes
(
Set
<
Class
<?
extends
Annotation
>>
autowiredAnnotationTypes
)
{
Assert
.
notEmpty
(
autowiredAnnotationTypes
,
"'autowiredAnnotationTypes' must not be empty"
);
...
...
@@ -191,8 +191,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
}
/**
* Set the name of a parameter of the annotation that specifies
* whether it is required.
* Set the name of a parameter of the annotation that specifies whether it is required.
* @see #setRequiredParameterValue(boolean)
*/
public
void
setRequiredParameterName
(
String
requiredParameterName
)
{
...
...
@@ -201,9 +200,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
/**
* Set the boolean value that marks a dependency as required
* <p>For example if using 'required=true' (the default),
* this value should be {@code true}; but if using
* 'optional=false', this value should be {@code false}.
* <p>For example if using 'required=true' (the default), this value should be
* {@code true}; but if using 'optional=false', this value should be {@code false}.
* @see #setRequiredParameterName(String)
*/
public
void
setRequiredParameterValue
(
boolean
requiredParameterValue
)
{
...
...
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
View file @
d2188a36
...
...
@@ -509,12 +509,21 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
// Generics potentially only match on the target class, not on the proxy...
RootBeanDefinition
mbd
=
getMergedLocalBeanDefinition
(
beanName
);
Class
<?>
targetType
=
mbd
.
getTargetType
();
if
(
targetType
!=
null
&&
targetType
!=
ClassUtils
.
getUserClass
(
beanInstance
)
&&
typeToMatch
.
isAssignableFrom
(
targetType
))
{
if
(
targetType
!=
null
&&
targetType
!=
ClassUtils
.
getUserClass
(
beanInstance
))
{
// Check raw class match as well, making sure it's exposed on the proxy.
Class
<?>
classToMatch
=
typeToMatch
.
resolve
();
return
(
classToMatch
==
null
||
classToMatch
.
isInstance
(
beanInstance
));
if
(
classToMatch
!=
null
&&
!
classToMatch
.
isInstance
(
beanInstance
))
{
return
false
;
}
if
(
typeToMatch
.
isAssignableFrom
(
targetType
))
{
return
true
;
}
}
ResolvableType
resolvableType
=
mbd
.
targetType
;
if
(
resolvableType
==
null
)
{
resolvableType
=
mbd
.
factoryMethodReturnType
;
}
return
(
resolvableType
!=
null
&&
typeToMatch
.
isAssignableFrom
(
resolvableType
));
}
}
return
false
;
...
...
@@ -982,7 +991,6 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@Override
public
BeanDefinition
getMergedBeanDefinition
(
String
name
)
throws
BeansException
{
String
beanName
=
transformedBeanName
(
name
);
// Efficiently check whether bean definition exists in this factory.
if
(!
containsBeanDefinition
(
beanName
)
&&
getParentBeanFactory
()
instanceof
ConfigurableBeanFactory
)
{
return
((
ConfigurableBeanFactory
)
getParentBeanFactory
()).
getMergedBeanDefinition
(
beanName
);
...
...
@@ -994,7 +1002,6 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@Override
public
boolean
isFactoryBean
(
String
name
)
throws
NoSuchBeanDefinitionException
{
String
beanName
=
transformedBeanName
(
name
);
Object
beanInstance
=
getSingleton
(
beanName
,
false
);
if
(
beanInstance
!=
null
)
{
return
(
beanInstance
instanceof
FactoryBean
);
...
...
@@ -1003,13 +1010,11 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
// null instance registered
return
false
;
}
// No singleton instance found -> check bean definition.
if
(!
containsBeanDefinition
(
beanName
)
&&
getParentBeanFactory
()
instanceof
ConfigurableBeanFactory
)
{
// No bean definition found in this factory -> delegate to parent.
return
((
ConfigurableBeanFactory
)
getParentBeanFactory
()).
isFactoryBean
(
name
);
}
return
isFactoryBean
(
beanName
,
getMergedLocalBeanDefinition
(
beanName
));
}
...
...
@@ -1367,6 +1372,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
*/
protected
Class
<?>
resolveBeanClass
(
final
RootBeanDefinition
mbd
,
String
beanName
,
final
Class
<?>...
typesToMatch
)
throws
CannotLoadBeanClassException
{
try
{
if
(
mbd
.
hasBeanClass
())
{
return
mbd
.
getBeanClass
();
...
...
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
View file @
d2188a36
...
...
@@ -1574,7 +1574,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
}
// Lenient fallback: dummy factory in case of original factory not found...
return
new
DefaultListableBeanFactory
();
DefaultListableBeanFactory
dummyFactory
=
new
DefaultListableBeanFactory
();
dummyFactory
.
serializationId
=
this
.
id
;
return
dummyFactory
;
}
}
...
...
spring-context/src/main/java/org/springframework/context/annotation/DependsOn.java
View file @
d2188a36
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -28,6 +28,12 @@ import java.lang.annotation.Target;
* does not explicitly depend on another through properties or constructor arguments,
* but rather depends on the side effects of another bean's initialization.
*
* <p>A depends-on declaration can specify both an initialization-time dependency and,
* in the case of singleton beans only, a corresponding destruction-time dependency.
* Dependent beans that define a depends-on relationship with a given bean are destroyed
* first, prior to the given bean itself being destroyed. Thus, a depends-on declaration
* can also control shutdown order.
*
* <p>May be used on any class directly or indirectly annotated with
* {@link org.springframework.stereotype.Component} or on methods annotated
* with {@link Bean}.
...
...
spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
View file @
d2188a36
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -16,9 +16,10 @@
package
org.springframework.context.event
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.LinkedHashSet
;
import
java.util.
Linked
List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -210,7 +211,7 @@ public abstract class AbstractApplicationEventMulticaster
private
Collection
<
ApplicationListener
<?>>
retrieveApplicationListeners
(
ResolvableType
eventType
,
Class
<?>
sourceType
,
ListenerRetriever
retriever
)
{
Linked
List
<
ApplicationListener
<?>>
allListeners
=
new
Linked
List
<
ApplicationListener
<?>>();
List
<
ApplicationListener
<?>>
allListeners
=
new
Array
List
<
ApplicationListener
<?>>();
Set
<
ApplicationListener
<?>>
listeners
;
Set
<
String
>
listenerBeans
;
synchronized
(
this
.
retrievalMutex
)
{
...
...
@@ -345,23 +346,20 @@ public abstract class AbstractApplicationEventMulticaster
*/
private
class
ListenerRetriever
{
public
final
Set
<
ApplicationListener
<?>>
applicationListeners
;
public
final
Set
<
ApplicationListener
<?>>
applicationListeners
=
new
LinkedHashSet
<
ApplicationListener
<?>>()
;
public
final
Set
<
String
>
applicationListenerBeans
;
public
final
Set
<
String
>
applicationListenerBeans
=
new
LinkedHashSet
<
String
>()
;
private
final
boolean
preFiltered
;
public
ListenerRetriever
(
boolean
preFiltered
)
{
this
.
applicationListeners
=
new
LinkedHashSet
<
ApplicationListener
<?>>();
this
.
applicationListenerBeans
=
new
LinkedHashSet
<
String
>();
this
.
preFiltered
=
preFiltered
;
}
public
Collection
<
ApplicationListener
<?>>
getApplicationListeners
()
{
LinkedList
<
ApplicationListener
<?>>
allListeners
=
new
LinkedList
<
ApplicationListener
<?>>();
for
(
ApplicationListener
<?>
listener
:
this
.
applicationListeners
)
{
allListeners
.
add
(
listener
);
}
List
<
ApplicationListener
<?>>
allListeners
=
new
ArrayList
<
ApplicationListener
<?>>(
this
.
applicationListeners
.
size
()
+
this
.
applicationListenerBeans
.
size
());
allListeners
.
addAll
(
this
.
applicationListeners
);
if
(!
this
.
applicationListenerBeans
.
isEmpty
())
{
BeanFactory
beanFactory
=
getBeanFactory
();
for
(
String
listenerBeanName
:
this
.
applicationListenerBeans
)
{
...
...
spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java
View file @
d2188a36
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -30,9 +30,9 @@ import org.springframework.beans.factory.DisposableBean;
import
org.springframework.beans.factory.InitializingBean
;
/**
* Base class for
classes that are setting up a
*
{@code
java.util.concurrent.
ExecutorService}
*
(typically a
{@link java.util.concurrent.ThreadPoolExecutor}).
* Base class for
setting up a {@link java.util.concurrent.ExecutorService}
*
(typically a {@link
java.util.concurrent.
ThreadPoolExecutor} or
* {@link java.util.concurrent.
Scheduled
ThreadPoolExecutor}).
* Defines common configuration settings and common lifecycle handling.
*
* @author Juergen Hoeller
...
...
@@ -40,6 +40,7 @@ import org.springframework.beans.factory.InitializingBean;
* @see java.util.concurrent.ExecutorService
* @see java.util.concurrent.Executors
* @see java.util.concurrent.ThreadPoolExecutor
* @see java.util.concurrent.ScheduledThreadPoolExecutor
*/
@SuppressWarnings
(
"serial"
)
public
abstract
class
ExecutorConfigurationSupport
extends
CustomizableThreadFactory
...
...
spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
View file @
d2188a36
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -136,8 +136,8 @@ import org.springframework.util.StringUtils;
* @author Mark Fisher
* @since 2.0
*/
public
class
ScriptFactoryPostProcessor
extends
InstantiationAwareBeanPostProcessorAdapter
implements
BeanClassLoaderAware
,
BeanFactoryAware
,
ResourceLoaderAware
,
DisposableBean
,
Ordered
{
public
class
ScriptFactoryPostProcessor
extends
InstantiationAwareBeanPostProcessorAdapter
implements
BeanClassLoaderAware
,
BeanFactoryAware
,
ResourceLoaderAware
,
DisposableBean
,
Ordered
{
/**
* The {@link org.springframework.core.io.Resource}-style prefix that denotes
...
...
@@ -160,6 +160,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
private
static
final
String
SCRIPTED_OBJECT_NAME_PREFIX
=
"scriptedObject."
;
/** Logger available to subclasses */
protected
final
Log
logger
=
LogFactory
.
getLog
(
getClass
());
...
...
@@ -221,7 +222,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
// since those are only meant to apply to beans defined in the original factory.
for
(
Iterator
<
BeanPostProcessor
>
it
=
this
.
scriptBeanFactory
.
getBeanPostProcessors
().
iterator
();
it
.
hasNext
();)
{
if
(
it
.
next
()
instanceof
AopInfrastructureBean
)
{
it
.
remove
();
it
.
remove
();
// effectively deprecated: use List.removeIf on Java 8+
}
}
}
...
...
@@ -236,6 +237,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
return
Integer
.
MIN_VALUE
;
}
@Override
public
Class
<?>
predictBeanType
(
Class
<?>
beanClass
,
String
beanName
)
{
// We only apply special treatment to ScriptFactory implementations here.
...
...
@@ -274,8 +276,8 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
if
(
ex
instanceof
BeanCreationException
&&
((
BeanCreationException
)
ex
).
getMostSpecificCause
()
instanceof
BeanCurrentlyInCreationException
)
{
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Could not determine scripted object type for bean '"
+
beanName
+
"': "
+
ex
.
getMessage
());
logger
.
trace
(
"Could not determine scripted object type for bean '"
+
beanName
+
"': "
+
ex
.
getMessage
());
}
}
else
{
...
...
spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java
View file @
d2188a36
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -28,6 +28,8 @@ import org.aopalliance.intercept.MethodInterceptor;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.hibernate.validator.HibernateValidator
;
import
org.springframework.beans.factory.FactoryBean
;
import
org.springframework.beans.factory.SmartFactoryBean
;
import
org.springframework.core.BridgeMethodResolver
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.util.ClassUtils
;
...
...
@@ -112,6 +114,11 @@ public class MethodValidationInterceptor implements MethodInterceptor {
@Override
@SuppressWarnings
(
"unchecked"
)
public
Object
invoke
(
MethodInvocation
invocation
)
throws
Throwable
{
// Avoid Validator invocation on FactoryBean.getObjectType/isSingleton
if
(
isFactoryBeanMetadataMethod
(
invocation
.
getMethod
()))
{
return
invocation
.
proceed
();
}
Class
<?>[]
groups
=
determineValidationGroups
(
invocation
);
if
(
forExecutablesMethod
!=
null
)
{
...
...
@@ -162,6 +169,27 @@ public class MethodValidationInterceptor implements MethodInterceptor {
}
}
private
boolean
isFactoryBeanMetadataMethod
(
Method
method
)
{
Class
<?>
clazz
=
method
.
getDeclaringClass
();
// Call from interface-based proxy handle, allowing for an efficient check?
if
(
clazz
.
isInterface
())
{
return
((
clazz
==
FactoryBean
.
class
||
clazz
==
SmartFactoryBean
.
class
)
&&
!
method
.
getName
().
equals
(
"getObject"
));
}
// Call from CGLIB proxy handle, potentially implementing a FactoryBean method?
Class
<?>
factoryBeanType
=
null
;
if
(
SmartFactoryBean
.
class
.
isAssignableFrom
(
clazz
))
{
factoryBeanType
=
SmartFactoryBean
.
class
;
}
else
if
(
FactoryBean
.
class
.
isAssignableFrom
(
clazz
))
{
factoryBeanType
=
FactoryBean
.
class
;
}
return
(
factoryBeanType
!=
null
&&
!
method
.
getName
().
equals
(
"getObject"
)
&&
ClassUtils
.
hasMethod
(
factoryBeanType
,
method
.
getName
(),
method
.
getParameterTypes
()));
}
/**
* Determine the validation groups to validate against for the given method invocation.
* <p>Default are the validation groups as specified in the {@link Validated} annotation
...
...
spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java
View file @
d2188a36
...
...
@@ -544,6 +544,10 @@ public class ConfigurationClassPostProcessorTests {
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
}
@Test
...
...
@@ -558,6 +562,78 @@ public class ConfigurationClassPostProcessorTests {
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
}
@Test
public
void
genericsBasedInjectionWithEarlyGenericsMatchingAndRawFactoryMethod
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawFactoryMethodRepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
String
[]
beanNames
=
beanFactory
.
getBeanNamesForType
(
Repository
.
class
);
assertTrue
(
ObjectUtils
.
containsElement
(
beanNames
,
"stringRepo"
));
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
0
,
beanNames
.
length
);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
0
,
beanNames
.
length
);
}
@Test
public
void
genericsBasedInjectionWithLateGenericsMatchingAndRawFactoryMethod
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawFactoryMethodRepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
beanFactory
.
preInstantiateSingletons
();
String
[]
beanNames
=
beanFactory
.
getBeanNamesForType
(
Repository
.
class
);
assertTrue
(
ObjectUtils
.
containsElement
(
beanNames
,
"stringRepo"
));
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
}
@Test
public
void
genericsBasedInjectionWithEarlyGenericsMatchingAndRawInstance
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawInstanceRepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
String
[]
beanNames
=
beanFactory
.
getBeanNamesForType
(
Repository
.
class
);
assertTrue
(
ObjectUtils
.
containsElement
(
beanNames
,
"stringRepo"
));
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
}
@Test
public
void
genericsBasedInjectionWithLateGenericsMatchingAndRawInstance
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawInstanceRepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
beanFactory
.
preInstantiateSingletons
();
String
[]
beanNames
=
beanFactory
.
getBeanNamesForType
(
Repository
.
class
);
assertTrue
(
ObjectUtils
.
containsElement
(
beanNames
,
"stringRepo"
));
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
}
@Test
...
...
@@ -577,6 +653,10 @@ public class ConfigurationClassPostProcessorTests {
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isCglibProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
...
...
@@ -598,12 +678,16 @@ public class ConfigurationClassPostProcessorTests {
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isCglibProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
@Test
public
void
genericsBasedInjectionWithLateGenericsMatchingOnCglibProxyAndRawFactoryMethod
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawRepositoryConfiguration
.
class
));
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
Raw
FactoryMethod
RepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
DefaultAdvisorAutoProxyCreator
autoProxyCreator
=
new
DefaultAdvisorAutoProxyCreator
();
autoProxyCreator
.
setProxyTargetClass
(
true
);
...
...
@@ -619,6 +703,35 @@ public class ConfigurationClassPostProcessorTests {
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isCglibProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
@Test
public
void
genericsBasedInjectionWithLateGenericsMatchingOnCglibProxyAndRawInstance
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawInstanceRepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
DefaultAdvisorAutoProxyCreator
autoProxyCreator
=
new
DefaultAdvisorAutoProxyCreator
();
autoProxyCreator
.
setProxyTargetClass
(
true
);
autoProxyCreator
.
setBeanFactory
(
beanFactory
);
beanFactory
.
addBeanPostProcessor
(
autoProxyCreator
);
beanFactory
.
registerSingleton
(
"traceInterceptor"
,
new
DefaultPointcutAdvisor
(
new
SimpleTraceInterceptor
()));
beanFactory
.
preInstantiateSingletons
();
String
[]
beanNames
=
beanFactory
.
getBeanNamesForType
(
Repository
.
class
);
assertTrue
(
ObjectUtils
.
containsElement
(
beanNames
,
"stringRepo"
));
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
Repository
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isCglibProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
...
...
@@ -638,6 +751,10 @@ public class ConfigurationClassPostProcessorTests {
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
RepositoryInterface
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isJdkDynamicProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
...
...
@@ -658,12 +775,16 @@ public class ConfigurationClassPostProcessorTests {
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
RepositoryInterface
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isJdkDynamicProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
@Test
public
void
genericsBasedInjectionWithLateGenericsMatchingOnJdkProxyAndRawFactoryMethod
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawRepositoryConfiguration
.
class
));
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
Raw
FactoryMethod
RepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
DefaultAdvisorAutoProxyCreator
autoProxyCreator
=
new
DefaultAdvisorAutoProxyCreator
();
autoProxyCreator
.
setBeanFactory
(
beanFactory
);
...
...
@@ -678,6 +799,34 @@ public class ConfigurationClassPostProcessorTests {
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
RepositoryInterface
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isJdkDynamicProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
@Test
public
void
genericsBasedInjectionWithLateGenericsMatchingOnJdkProxyAndRawInstance
()
{
beanFactory
.
registerBeanDefinition
(
"configClass"
,
new
RootBeanDefinition
(
RawInstanceRepositoryConfiguration
.
class
));
new
ConfigurationClassPostProcessor
().
postProcessBeanFactory
(
beanFactory
);
DefaultAdvisorAutoProxyCreator
autoProxyCreator
=
new
DefaultAdvisorAutoProxyCreator
();
autoProxyCreator
.
setBeanFactory
(
beanFactory
);
beanFactory
.
addBeanPostProcessor
(
autoProxyCreator
);
beanFactory
.
registerSingleton
(
"traceInterceptor"
,
new
DefaultPointcutAdvisor
(
new
SimpleTraceInterceptor
()));
beanFactory
.
preInstantiateSingletons
();
String
[]
beanNames
=
beanFactory
.
getBeanNamesForType
(
RepositoryInterface
.
class
);
assertTrue
(
ObjectUtils
.
containsElement
(
beanNames
,
"stringRepo"
));
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
RepositoryInterface
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
beanNames
=
beanFactory
.
getBeanNamesForType
(
ResolvableType
.
forClassWithGenerics
(
RepositoryInterface
.
class
,
String
.
class
));
assertEquals
(
1
,
beanNames
.
length
);
assertEquals
(
"stringRepo"
,
beanNames
[
0
]);
assertTrue
(
AopUtils
.
isJdkDynamicProxy
(
beanFactory
.
getBean
(
"stringRepo"
)));
}
...
...
@@ -980,7 +1129,7 @@ public class ConfigurationClassPostProcessorTests {
}
@Configuration
public
static
class
RawRepositoryConfiguration
{
public
static
class
Raw
FactoryMethod
RepositoryConfiguration
{
@Bean
public
Repository
stringRepo
()
{
...
...
@@ -993,6 +1142,21 @@ public class ConfigurationClassPostProcessorTests {
}
}
@Configuration
public
static
class
RawInstanceRepositoryConfiguration
{
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
@Bean
public
Repository
<
String
>
stringRepo
()
{
return
new
Repository
()
{
@Override
public
String
toString
()
{
return
"Repository<String>"
;
}
};
}
}
@Configuration
public
static
class
ScopedRepositoryConfiguration
{
...
...
spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
View file @
d2188a36
...
...
@@ -365,7 +365,8 @@ public class EnableAsyncTests {
@EnableAsync
static
class
AsyncConfigWithMockito
{
@Bean
@Lazy
@Bean
@Lazy
public
AsyncBean
asyncBean
()
{
return
Mockito
.
mock
(
AsyncBean
.
class
);
}
...
...
spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java
View file @
d2188a36
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -23,28 +23,29 @@ import javax.naming.NamingException;
import
org.springframework.jndi.JndiTemplate
;
/**
* Simple extension of the JndiTemplate class that always returns
* a given object. Very useful for testing. Effectively a mock object.
* Simple extension of the JndiTemplate class that always returns a given object.
*
* <p>Very useful for testing. Effectively a mock object.
*
* @author Rod Johnson
* @author Juergen Hoeller
*/
public
class
ExpectedLookupTemplate
extends
JndiTemplate
{
private
final
Map
<
String
,
Object
>
jndiObjects
=
new
ConcurrentHashMap
<
String
,
Object
>();
private
final
Map
<
String
,
Object
>
jndiObjects
=
new
ConcurrentHashMap
<
String
,
Object
>(
16
);
/**
* Construct a new JndiTemplate that will always return given objects
*
for
given names. To be populated through {@code addObject} calls.
* Construct a new JndiTemplate that will always return given objects
for
* given names. To be populated through {@code addObject} calls.
* @see #addObject(String, Object)
*/
public
ExpectedLookupTemplate
()
{
}
/**
* Construct a new JndiTemplate that will always return the
*
given object,
but honour only requests for the given name.
* Construct a new JndiTemplate that will always return the
given object,
* but honour only requests for the given name.
* @param name the name the client is expected to look up
* @param object the object that will be returned
*/
...
...
@@ -54,8 +55,7 @@ public class ExpectedLookupTemplate extends JndiTemplate {
/**
* Add the given object to the list of JNDI objects that this
* template will expose.
* Add the given object to the list of JNDI objects that this template will expose.
* @param name the name the client is expected to look up
* @param object the object that will be returned
*/
...
...
@@ -63,11 +63,10 @@ public class ExpectedLookupTemplate extends JndiTemplate {
this
.
jndiObjects
.
put
(
name
,
object
);
}
/**
* If the name is the expected name specified in the constructor,
*
return the
object provided in the constructor. If the name is
*
unexpected, a
respective NamingException gets thrown.
* If the name is the expected name specified in the constructor,
return the
* object provided in the constructor. If the name is
unexpected, a
* respective NamingException gets thrown.
*/
@Override
public
Object
lookup
(
String
name
)
throws
NamingException
{
...
...
spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java
View file @
d2188a36
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -26,6 +26,7 @@ import javax.naming.spi.NamingManager;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
/**
...
...
@@ -35,13 +36,14 @@ import org.springframework.util.ClassUtils;
* configure JNDI appropriately, so that {@code new InitialContext()}
* will expose the required objects. Also usable for standalone applications,
* e.g. for binding a JDBC DataSource to a well-known JNDI location, to be
* able to use traditional J2EE data access code outside of a J2EE container.
* able to use traditional Java EE data access code outside of a Java EE
* container.
*
* <p>There are various choices for DataSource implementations:
* <ul>
* <li>{@code SingleConnectionDataSource} (using the same Connection for all getConnection calls)
* <li>{@code DriverManagerDataSource} (creating a new Connection on each getConnection call)
* <li>Apache's
Jakarta
Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
* <li>Apache's Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
* </ul>
*
* <p>Typical usage in bootstrap code:
...
...
@@ -98,7 +100,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
/**
* If no SimpleNamingContextBuilder is already configuring JNDI,
* create and activate one. Otherwise take the existing activate
* create and activate one. Otherwise take the existing activate
d
* SimpleNamingContextBuilder, clear it and return it.
* <p>This is mainly intended for test suites that want to
* reinitialize JNDI bindings from scratch repeatedly.
...
...
@@ -137,12 +139,10 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
logger
.
info
(
"Activating simple JNDI environment"
);
synchronized
(
initializationLock
)
{
if
(!
initialized
)
{
if
(
NamingManager
.
hasInitialContextFactoryBuilder
())
{
throw
new
IllegalStateException
(
Assert
.
state
(!
NamingManager
.
hasInitialContextFactoryBuilder
(),
"Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. "
+
"Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, "
+
"with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."
);
}
NamingManager
.
setInitialContextFactoryBuilder
(
this
);
initialized
=
true
;
}
...
...
Prev
1
2
3
4
5
6
Next