Polishing
This commit is contained in:
@@ -972,6 +972,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(getClass().getName());
|
||||
@@ -985,6 +986,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A handler for a specific property.
|
||||
*/
|
||||
protected abstract static class PropertyHandler {
|
||||
|
||||
private final Class<?> propertyType;
|
||||
@@ -1035,6 +1039,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Holder class used to store property tokens.
|
||||
*/
|
||||
protected static class PropertyTokenHolder {
|
||||
|
||||
public String canonicalName;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -242,18 +242,19 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
throws BeansException;
|
||||
|
||||
/**
|
||||
* Find all names of beans whose {@code Class} has the supplied {@link Annotation}
|
||||
* Find all names of beans which are annotated with the supplied {@link Annotation}
|
||||
* 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
|
||||
* @see #findAnnotationOnBean
|
||||
*/
|
||||
String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType);
|
||||
|
||||
/**
|
||||
* Find all beans whose {@code Class} has the supplied {@link Annotation} type,
|
||||
* Find all beans which are annotated with 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.
|
||||
@@ -262,18 +263,21 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
* keys and the corresponding bean instances as values
|
||||
* @throws BeansException if a bean could not be created
|
||||
* @since 3.0
|
||||
* @see #findAnnotationOnBean
|
||||
*/
|
||||
Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws BeansException;
|
||||
|
||||
/**
|
||||
* Find an {@link Annotation} of {@code annotationType} on the specified
|
||||
* bean, traversing its interfaces and super classes if no annotation can be
|
||||
* found on the given class itself.
|
||||
* Find an {@link Annotation} of {@code annotationType} on the specified bean,
|
||||
* traversing its interfaces and super classes if no annotation can be 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
|
||||
* @param annotationType the type of annotation to look for
|
||||
* @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
|
||||
* @see #getBeanNamesForAnnotation
|
||||
* @see #getBeansWithAnnotation
|
||||
*/
|
||||
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
||||
throws NoSuchBeanDefinitionException;
|
||||
|
||||
@@ -318,7 +318,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
|
||||
/**
|
||||
* Apply the provided default values to this bean.
|
||||
* @param defaults the defaults to apply
|
||||
* @param defaults the default settings to apply
|
||||
* @since 2.5
|
||||
*/
|
||||
public void applyDefaults(BeanDefinitionDefaults defaults) {
|
||||
setLazyInit(defaults.isLazyInit());
|
||||
@@ -478,6 +479,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
/**
|
||||
* Return whether this bean should be lazily initialized, i.e. not
|
||||
* eagerly instantiated on startup. Only applicable to a singleton bean.
|
||||
* @return whether to apply lazy-init semantics ({@code false} by default)
|
||||
*/
|
||||
@Override
|
||||
public boolean isLazyInit() {
|
||||
@@ -486,8 +488,9 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
|
||||
/**
|
||||
* Set the autowire mode. This determines whether any automagical detection
|
||||
* and setting of bean references will happen. Default is AUTOWIRE_NO,
|
||||
* which means there's no autowire.
|
||||
* and setting of bean references will happen. Default is AUTOWIRE_NO
|
||||
* which means there won't be convention-based autowiring by name or type
|
||||
* (however, there may still be explicit annotation-driven autowiring).
|
||||
* @param autowireMode the autowire mode to set.
|
||||
* Must be one of the constants defined in this class.
|
||||
* @see #AUTOWIRE_NO
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -22,57 +22,99 @@ import org.springframework.util.StringUtils;
|
||||
* A simple holder for {@code BeanDefinition} property defaults.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5
|
||||
*/
|
||||
public class BeanDefinitionDefaults {
|
||||
|
||||
private boolean lazyInit;
|
||||
|
||||
private int dependencyCheck = AbstractBeanDefinition.DEPENDENCY_CHECK_NONE;
|
||||
|
||||
private int autowireMode = AbstractBeanDefinition.AUTOWIRE_NO;
|
||||
|
||||
private int dependencyCheck = AbstractBeanDefinition.DEPENDENCY_CHECK_NONE;
|
||||
|
||||
private String initMethodName;
|
||||
|
||||
private String destroyMethodName;
|
||||
|
||||
|
||||
/**
|
||||
* Set whether beans should be lazily initialized by default.
|
||||
* <p>If {@code false}, the bean will get instantiated on startup by bean
|
||||
* factories that perform eager initialization of singletons.
|
||||
*/
|
||||
public void setLazyInit(boolean lazyInit) {
|
||||
this.lazyInit = lazyInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether beans should be lazily initialized by default, i.e. not
|
||||
* eagerly instantiated on startup. Only applicable to singleton beans.
|
||||
* @return whether to apply lazy-init semantics ({@code false} by default)
|
||||
*/
|
||||
public boolean isLazyInit() {
|
||||
return this.lazyInit;
|
||||
}
|
||||
|
||||
public void setDependencyCheck(int dependencyCheck) {
|
||||
this.dependencyCheck = dependencyCheck;
|
||||
}
|
||||
|
||||
public int getDependencyCheck() {
|
||||
return this.dependencyCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the autowire mode. This determines whether any automagical detection
|
||||
* and setting of bean references will happen. Default is AUTOWIRE_NO
|
||||
* which means there won't be convention-based autowiring by name or type
|
||||
* (however, there may still be explicit annotation-driven autowiring).
|
||||
* @param autowireMode the autowire mode to set.
|
||||
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
|
||||
*/
|
||||
public void setAutowireMode(int autowireMode) {
|
||||
this.autowireMode = autowireMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default autowire mode.
|
||||
*/
|
||||
public int getAutowireMode() {
|
||||
return this.autowireMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dependency check code.
|
||||
* @param dependencyCheck the code to set.
|
||||
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
|
||||
*/
|
||||
public void setDependencyCheck(int dependencyCheck) {
|
||||
this.dependencyCheck = dependencyCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default dependency check code.
|
||||
*/
|
||||
public int getDependencyCheck() {
|
||||
return this.dependencyCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the default initializer method.
|
||||
*/
|
||||
public void setInitMethodName(String initMethodName) {
|
||||
this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the default initializer method.
|
||||
*/
|
||||
public String getInitMethodName() {
|
||||
return this.initMethodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the default destroy method.
|
||||
*/
|
||||
public void setDestroyMethodName(String destroyMethodName) {
|
||||
this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the default destroy method.
|
||||
*/
|
||||
public String getDestroyMethodName() {
|
||||
return this.destroyMethodName;
|
||||
}
|
||||
|
||||
@@ -566,12 +566,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a {@link Annotation} of {@code annotationType} on the specified
|
||||
* bean, traversing its interfaces and super classes if no annotation can be
|
||||
* found on the given class itself, as well as checking its raw bean class
|
||||
* if not found on the exposed bean reference (e.g. in case of a proxy).
|
||||
*/
|
||||
@Override
|
||||
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
||||
throws NoSuchBeanDefinitionException {
|
||||
@@ -582,14 +576,12 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
ann = AnnotationUtils.findAnnotation(beanType, annotationType);
|
||||
}
|
||||
if (ann == null && containsBeanDefinition(beanName)) {
|
||||
BeanDefinition bd = getMergedBeanDefinition(beanName);
|
||||
if (bd instanceof AbstractBeanDefinition) {
|
||||
AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
|
||||
if (abd.hasBeanClass()) {
|
||||
Class<?> beanClass = abd.getBeanClass();
|
||||
if (beanClass != beanType) {
|
||||
ann = AnnotationUtils.findAnnotation(beanClass, annotationType);
|
||||
}
|
||||
// Check raw bean class, e.g. in case of a proxy.
|
||||
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
|
||||
if (bd.hasBeanClass()) {
|
||||
Class<?> beanClass = bd.getBeanClass();
|
||||
if (beanClass != beanType) {
|
||||
ann = AnnotationUtils.findAnnotation(beanClass, annotationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1756,10 +1748,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
|
||||
@Override
|
||||
public Object getOrderSource(Object obj) {
|
||||
RootBeanDefinition beanDefinition = getRootBeanDefinition(this.instancesToBeanNames.get(obj));
|
||||
if (beanDefinition == null) {
|
||||
String beanName = this.instancesToBeanNames.get(obj);
|
||||
if (beanName == null || !containsBeanDefinition(beanName)) {
|
||||
return null;
|
||||
}
|
||||
RootBeanDefinition beanDefinition = getMergedLocalBeanDefinition(beanName);
|
||||
List<Object> sources = new ArrayList<Object>(2);
|
||||
Method factoryMethod = beanDefinition.getResolvedFactoryMethod();
|
||||
if (factoryMethod != null) {
|
||||
@@ -1771,16 +1764,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
}
|
||||
return sources.toArray();
|
||||
}
|
||||
|
||||
private RootBeanDefinition getRootBeanDefinition(String beanName) {
|
||||
if (beanName != null && containsBeanDefinition(beanName)) {
|
||||
BeanDefinition bd = getMergedBeanDefinition(beanName);
|
||||
if (bd instanceof RootBeanDefinition) {
|
||||
return (RootBeanDefinition) bd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ public class BeanDefinitionParserDelegate {
|
||||
/**
|
||||
* Populate the given DocumentDefaultsDefinition instance with the default lazy-init,
|
||||
* autowire, dependency check settings, init-method, destroy-method and merge settings.
|
||||
* Support nested 'beans' element use cases by falling back to <literal>parentDefaults</literal>
|
||||
* Support nested 'beans' element use cases by falling back to {@code parentDefaults}
|
||||
* in case the defaults are not explicitly set locally.
|
||||
* @param defaults the defaults to populate
|
||||
* @param parentDefaults the parent BeanDefinitionParserDelegate (if any) defaults to fall back to
|
||||
@@ -401,9 +401,9 @@ public class BeanDefinitionParserDelegate {
|
||||
*/
|
||||
public BeanDefinitionDefaults getBeanDefinitionDefaults() {
|
||||
BeanDefinitionDefaults bdd = new BeanDefinitionDefaults();
|
||||
bdd.setLazyInit("TRUE".equalsIgnoreCase(this.defaults.getLazyInit()));
|
||||
bdd.setDependencyCheck(getDependencyCheck(DEFAULT_VALUE));
|
||||
bdd.setLazyInit(TRUE_VALUE.equalsIgnoreCase(this.defaults.getLazyInit()));
|
||||
bdd.setAutowireMode(getAutowireMode(DEFAULT_VALUE));
|
||||
bdd.setDependencyCheck(getDependencyCheck(DEFAULT_VALUE));
|
||||
bdd.setInitMethodName(this.defaults.getInitMethod());
|
||||
bdd.setDestroyMethodName(this.defaults.getDestroyMethod());
|
||||
return bdd;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -45,7 +45,7 @@ import org.springframework.stereotype.Component;
|
||||
*
|
||||
* <h3>Via {@code AnnotationConfigApplicationContext}</h3>
|
||||
*
|
||||
* {@code @Configuration} classes are typically bootstrapped using either
|
||||
* <p>{@code @Configuration} classes are typically bootstrapped using either
|
||||
* {@link AnnotationConfigApplicationContext} or its web-capable variant,
|
||||
* {@link org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
||||
* AnnotationConfigWebApplicationContext}. A simple example with the former follows:
|
||||
@@ -58,23 +58,25 @@ import org.springframework.stereotype.Component;
|
||||
* // use myBean ...
|
||||
* </pre>
|
||||
*
|
||||
* See {@link AnnotationConfigApplicationContext} Javadoc for further details and see
|
||||
* <p>See the {@link AnnotationConfigApplicationContext} javadocs for further details, and see
|
||||
* {@link org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
||||
* AnnotationConfigWebApplicationContext} for {@code web.xml} configuration instructions.
|
||||
* AnnotationConfigWebApplicationContext} for web configuration instructions in a
|
||||
* {@code Servlet} container.
|
||||
*
|
||||
* <h3>Via Spring {@code <beans>} XML</h3>
|
||||
*
|
||||
* <p>As an alternative to registering {@code @Configuration} classes directly against an
|
||||
* {@code AnnotationConfigApplicationContext}, {@code @Configuration} classes may be
|
||||
* declared as normal {@code <bean>} definitions within Spring XML files:
|
||||
* <pre class="code">
|
||||
* {@code
|
||||
* <beans>
|
||||
* <context:annotation-config/>
|
||||
* <bean class="com.acme.AppConfig"/>
|
||||
* </beans>}</pre>
|
||||
*
|
||||
* In the example above, {@code <context:annotation-config/>} is required in order to
|
||||
* <pre class="code">
|
||||
* <beans>
|
||||
* <context:annotation-config/>
|
||||
* <bean class="com.acme.AppConfig"/>
|
||||
* </beans>
|
||||
* </pre>
|
||||
*
|
||||
* <p>In the example above, {@code <context:annotation-config/>} is required in order to
|
||||
* enable {@link ConfigurationClassPostProcessor} and other annotation-related
|
||||
* post processors that facilitate handling {@code @Configuration} classes.
|
||||
*
|
||||
@@ -85,11 +87,12 @@ import org.springframework.stereotype.Component;
|
||||
* Spring XML's {@code <context:component-scan/>} element) and therefore may also take
|
||||
* advantage of {@link Autowired @Autowired}/{@link javax.inject.Inject @Inject}
|
||||
* like any regular {@code @Component}. In particular, if a single constructor is present
|
||||
* autowiring semantics will be applied transparently:
|
||||
* autowiring semantics will be applied transparently for that constructor:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
* public class AppConfig {
|
||||
*
|
||||
* private final SomeBean someBean;
|
||||
*
|
||||
* public AppConfig(SomeBean someBean) {
|
||||
@@ -111,15 +114,15 @@ import org.springframework.stereotype.Component;
|
||||
* // various @Bean definitions ...
|
||||
* }</pre>
|
||||
*
|
||||
* See the {@link ComponentScan @ComponentScan} javadoc for details.
|
||||
* <p>See the {@link ComponentScan @ComponentScan} javadocs for details.
|
||||
*
|
||||
* <h2>Working with externalized values</h2>
|
||||
*
|
||||
* <h3>Using the {@code Environment} API</h3>
|
||||
*
|
||||
* Externalized values may be looked up by injecting the Spring
|
||||
* <p>Externalized values may be looked up by injecting the Spring
|
||||
* {@link org.springframework.core.env.Environment} into a {@code @Configuration}
|
||||
* class the usual (e.g. using the {@code @Autowired} annotation):
|
||||
* class — for example, using the {@code @Autowired} annotation:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
@@ -135,10 +138,10 @@ import org.springframework.stereotype.Component;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* Properties resolved through the {@code Environment} reside in one or more "property
|
||||
* <p>Properties resolved through the {@code Environment} reside in one or more "property
|
||||
* source" objects, and {@code @Configuration} classes may contribute property sources to
|
||||
* the {@code Environment} object using
|
||||
* the {@link org.springframework.core.env.PropertySources @PropertySources} annotation:
|
||||
* the {@code Environment} object using the {@link PropertySource @PropertySource}
|
||||
* annotation:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
@@ -153,12 +156,12 @@ import org.springframework.stereotype.Component;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* See {@link org.springframework.core.env.Environment Environment}
|
||||
* and {@link PropertySource @PropertySource} Javadoc for further details.
|
||||
* <p>See the {@link org.springframework.core.env.Environment Environment}
|
||||
* and {@link PropertySource @PropertySource} javadocs for further details.
|
||||
*
|
||||
* <h3>Using the {@code @Value} annotation</h3>
|
||||
*
|
||||
* Externalized values may be 'wired into' {@code @Configuration} classes using
|
||||
* <p>Externalized values may be injected into {@code @Configuration} classes using
|
||||
* the {@link Value @Value} annotation:
|
||||
*
|
||||
* <pre class="code">
|
||||
@@ -174,13 +177,23 @@ import org.springframework.stereotype.Component;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* This approach is most useful when using Spring's
|
||||
* <p>This approach is often used in conjunction with Spring's
|
||||
* {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer
|
||||
* PropertySourcesPlaceholderConfigurer}, usually enabled via XML with
|
||||
* {@code <context:property-placeholder/>}. See the section below on composing
|
||||
* {@code @Configuration} classes with Spring XML using {@code @ImportResource},
|
||||
* see {@link Value @Value} Javadoc, and see {@link Bean @Bean} Javadoc for details on working with
|
||||
* {@code BeanFactoryPostProcessor} types such as
|
||||
* PropertySourcesPlaceholderConfigurer} that can be enabled <em>automatically</em>
|
||||
* in XML configuration via {@code <context:property-placeholder/>} or <em>explicitly</em>
|
||||
* in a {@code @Configuration} class via a dedicated {@code static} {@code @Bean} method
|
||||
* (see "a note on BeanFactoryPostProcessor-returning {@code @Bean} methods" of
|
||||
* {@link Bean @Bean}'s javadocs for details). Note, however, that explicit registration
|
||||
* of a {@code PropertySourcesPlaceholderConfigurer} via a {@code static} {@code @Bean}
|
||||
* method is typically only required if you need to customize configuration such as the
|
||||
* placeholder syntax, etc. Specifically, if no bean post-processor (such as a
|
||||
* {@code PropertySourcesPlaceholderConfigurer}) has registered an <em>embedded value
|
||||
* resolver</em> for the {@code ApplicationContext}, Spring will register a default
|
||||
* <em>embedded value resolver</em> which resolves placeholders against property sources
|
||||
* registered in the {@code Environment}. See the section below on composing
|
||||
* {@code @Configuration} classes with Spring XML using {@code @ImportResource}; see
|
||||
* the {@link Value @Value} javadocs; and see the {@link Bean @Bean} javadocs for details
|
||||
* on working with {@code BeanFactoryPostProcessor} types such as
|
||||
* {@code PropertySourcesPlaceholderConfigurer}.
|
||||
*
|
||||
* <h2>Composing {@code @Configuration} classes</h2>
|
||||
@@ -188,9 +201,9 @@ import org.springframework.stereotype.Component;
|
||||
* <h3>With the {@code @Import} annotation</h3>
|
||||
*
|
||||
* <p>{@code @Configuration} classes may be composed using the {@link Import @Import} annotation,
|
||||
* not unlike the way that {@code <import>} works in Spring XML. Because
|
||||
* similar to the way that {@code <import>} works in Spring XML. Because
|
||||
* {@code @Configuration} objects are managed as Spring beans within the container,
|
||||
* imported configurations may be injected the usual way (e.g. via constructor injection):
|
||||
* imported configurations may be injected — for example, via constructor injection:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
@@ -219,7 +232,7 @@ import org.springframework.stereotype.Component;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* Now both {@code AppConfig} and the imported {@code DatabaseConfig} can be bootstrapped
|
||||
* <p>Now both {@code AppConfig} and the imported {@code DatabaseConfig} can be bootstrapped
|
||||
* by registering only {@code AppConfig} against the Spring context:
|
||||
*
|
||||
* <pre class="code">
|
||||
@@ -227,7 +240,7 @@ import org.springframework.stereotype.Component;
|
||||
*
|
||||
* <h3>With the {@code @Profile} annotation</h3>
|
||||
*
|
||||
* {@code @Configuration} classes may be marked with the {@link Profile @Profile} annotation to
|
||||
* <p>{@code @Configuration} classes may be marked with the {@link Profile @Profile} annotation to
|
||||
* indicate they should be processed only if a given profile or profiles are <em>active</em>:
|
||||
*
|
||||
* <pre class="code">
|
||||
@@ -251,8 +264,8 @@ import org.springframework.stereotype.Component;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* Alternatively, you may also declare profile conditions at the {@code @Bean} method level,
|
||||
* e.g. for alternative bean variants within the same configuration class:
|
||||
* <p>Alternatively, you may also declare profile conditions at the {@code @Bean} method level
|
||||
* — for example, for alternative bean variants within the same configuration class:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
@@ -267,16 +280,16 @@ import org.springframework.stereotype.Component;
|
||||
* public DataSource productionDatabase() { ... }
|
||||
* }</pre>
|
||||
*
|
||||
* See the {@link Profile @Profile} and {@link org.springframework.core.env.Environment}
|
||||
* <p>See the {@link Profile @Profile} and {@link org.springframework.core.env.Environment}
|
||||
* javadocs for further details.
|
||||
*
|
||||
* <h3>With Spring XML using the {@code @ImportResource} annotation</h3>
|
||||
*
|
||||
* As mentioned above, {@code @Configuration} classes may be declared as regular Spring
|
||||
* <p>As mentioned above, {@code @Configuration} classes may be declared as regular Spring
|
||||
* {@code <bean>} definitions within Spring XML files. It is also possible to
|
||||
* import Spring XML configuration files into {@code @Configuration} classes using
|
||||
* the {@link ImportResource @ImportResource} annotation. Bean definitions imported from
|
||||
* XML can be injected the usual way (e.g. using the {@code Inject} annotation):
|
||||
* XML can be injected — for example, using the {@code @Inject} annotation:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
@@ -294,7 +307,7 @@ import org.springframework.stereotype.Component;
|
||||
*
|
||||
* <h3>With nested {@code @Configuration} classes</h3>
|
||||
*
|
||||
* {@code @Configuration} classes may be nested within one another as follows:
|
||||
* <p>{@code @Configuration} classes may be nested within one another as follows:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
@@ -316,11 +329,11 @@ import org.springframework.stereotype.Component;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* When bootstrapping such an arrangement, only {@code AppConfig} need be registered
|
||||
* <p>When bootstrapping such an arrangement, only {@code AppConfig} need be registered
|
||||
* against the application context. By virtue of being a nested {@code @Configuration}
|
||||
* class, {@code DatabaseConfig} <em>will be registered automatically</em>. This avoids
|
||||
* the need to use an {@code @Import} annotation when the relationship between
|
||||
* {@code AppConfig} {@code DatabaseConfig} is already implicitly clear.
|
||||
* {@code AppConfig} and {@code DatabaseConfig} is already implicitly clear.
|
||||
*
|
||||
* <p>Note also that nested {@code @Configuration} classes can be used to good effect
|
||||
* with the {@code @Profile} annotation to provide two options of the same bean to the
|
||||
@@ -336,13 +349,13 @@ import org.springframework.stereotype.Component;
|
||||
*
|
||||
* <h2>Testing support for {@code @Configuration} classes</h2>
|
||||
*
|
||||
* The Spring <em>TestContext framework</em> available in the {@code spring-test} module
|
||||
* provides the {@code @ContextConfiguration} annotation, which as of Spring 3.1 can
|
||||
* accept an array of {@code @Configuration} {@code Class} objects:
|
||||
* <p>The Spring <em>TestContext framework</em> available in the {@code spring-test} module
|
||||
* provides the {@code @ContextConfiguration} annotation which can accept an array of
|
||||
* {@code @Configuration} {@code Class} objects:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @RunWith(SpringJUnit4ClassRunner.class)
|
||||
* @ContextConfiguration(classes={AppConfig.class, DatabaseConfig.class})
|
||||
* @RunWith(SpringRunner.class)
|
||||
* @ContextConfiguration(classes = {AppConfig.class, DatabaseConfig.class})
|
||||
* public class MyTests {
|
||||
*
|
||||
* @Autowired MyBean myBean;
|
||||
@@ -355,14 +368,16 @@ import org.springframework.stereotype.Component;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* See TestContext framework reference documentation for details.
|
||||
* <p>See the
|
||||
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#testcontext-framework">TestContext framework</a>
|
||||
* reference documentation for details.
|
||||
*
|
||||
* <h2>Enabling built-in Spring features using {@code @Enable} annotations</h2>
|
||||
*
|
||||
* Spring features such as asynchronous method execution, scheduled task execution,
|
||||
* <p>Spring features such as asynchronous method execution, scheduled task execution,
|
||||
* annotation driven transaction management, and even Spring MVC can be enabled and
|
||||
* configured from {@code @Configuration}
|
||||
* classes using their respective "{@code @Enable}" annotations. See
|
||||
* configured from {@code @Configuration} classes using their respective "{@code @Enable}"
|
||||
* annotations. See
|
||||
* {@link org.springframework.scheduling.annotation.EnableAsync @EnableAsync},
|
||||
* {@link org.springframework.scheduling.annotation.EnableScheduling @EnableScheduling},
|
||||
* {@link org.springframework.transaction.annotation.EnableTransactionManagement @EnableTransactionManagement},
|
||||
@@ -405,15 +420,16 @@ import org.springframework.stereotype.Component;
|
||||
public @interface Configuration {
|
||||
|
||||
/**
|
||||
* Explicitly specify the name of the Spring bean definition associated
|
||||
* with this Configuration class. If left unspecified (the common case),
|
||||
* a bean name will be automatically generated.
|
||||
* <p>The custom name applies only if the Configuration class is picked up via
|
||||
* component scanning or supplied directly to a {@link AnnotationConfigApplicationContext}.
|
||||
* If the Configuration class is registered as a traditional XML bean definition,
|
||||
* the name/id of the bean element will take precedence.
|
||||
* @return the suggested component name, if any (or empty String otherwise)
|
||||
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
|
||||
* Explicitly specify the name of the Spring bean definition associated with the
|
||||
* {@code @Configuration} class. If left unspecified (the common case), a bean
|
||||
* name will be automatically generated.
|
||||
* <p>The custom name applies only if the {@code @Configuration} class is picked
|
||||
* up via component scanning or supplied directly to an
|
||||
* {@link AnnotationConfigApplicationContext}. If the {@code @Configuration} class
|
||||
* is registered as a traditional XML bean definition, the name/id of the bean
|
||||
* element will take precedence.
|
||||
* @return the explicit component name, if any (or empty String otherwise)
|
||||
* @see AnnotationBeanNameGenerator
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -29,7 +29,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
* In the general case, the keys are returned as a List containing one Map
|
||||
* for each row of keys.
|
||||
*
|
||||
* <p>Most applications only use on key per row and process only one row at a
|
||||
* <p>Most applications only use one key per row and process only one row at a
|
||||
* time in an insert statement. In these cases, just call {@code getKey}
|
||||
* to retrieve the key. The returned value is a Number here, which is the
|
||||
* usual type for auto-generated keys.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -33,12 +33,12 @@ import static org.junit.Assert.*;
|
||||
public class BeanPropertySqlParameterSourceTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void withNullBeanPassedToCtor() throws Exception {
|
||||
public void withNullBeanPassedToCtor() {
|
||||
new BeanPropertySqlParameterSource(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getValueWhereTheUnderlyingBeanHasNoSuchProperty() throws Exception {
|
||||
public void getValueWhereTheUnderlyingBeanHasNoSuchProperty() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean());
|
||||
source.getValue("thisPropertyDoesNotExist");
|
||||
}
|
||||
@@ -65,19 +65,19 @@ public class BeanPropertySqlParameterSourceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasValueWhereTheUnderlyingBeanHasNoSuchProperty() throws Exception {
|
||||
public void hasValueWhereTheUnderlyingBeanHasNoSuchProperty() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean());
|
||||
assertFalse(source.hasValue("thisPropertyDoesNotExist"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getValueWhereTheUnderlyingBeanPropertyIsNotReadable() throws Exception {
|
||||
public void getValueWhereTheUnderlyingBeanPropertyIsNotReadable() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties());
|
||||
source.getValue("noOp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasValueWhereTheUnderlyingBeanPropertyIsNotReadable() throws Exception {
|
||||
public void hasValueWhereTheUnderlyingBeanPropertyIsNotReadable() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties());
|
||||
assertFalse(source.hasValue("noOp"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2019 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,21 +26,21 @@ import static org.junit.Assert.*;
|
||||
* @author Rick Evans
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public final class MapSqlParameterSourceTests {
|
||||
public class MapSqlParameterSourceTests {
|
||||
|
||||
@Test
|
||||
public void nullParameterValuesPassedToCtorIsOk() throws Exception {
|
||||
public void nullParameterValuesPassedToCtorIsOk() {
|
||||
new MapSqlParameterSource(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getValueChokesIfParameterIsNotPresent() throws Exception {
|
||||
public void getValueChokesIfParameterIsNotPresent() {
|
||||
MapSqlParameterSource source = new MapSqlParameterSource();
|
||||
source.getValue("pechorin was right!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sqlParameterValueRegistersSqlType() throws Exception {
|
||||
public void sqlParameterValueRegistersSqlType() {
|
||||
MapSqlParameterSource msps = new MapSqlParameterSource("FOO", new SqlParameterValue(2, "Foo"));
|
||||
assertEquals("Correct SQL Type not registered", 2, msps.getSqlType("FOO"));
|
||||
MapSqlParameterSource msps2 = new MapSqlParameterSource();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -112,22 +112,29 @@ import org.springframework.util.xml.StaxUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.0
|
||||
* @see #setContextPath(String)
|
||||
* @see #setClassesToBeBound(Class[])
|
||||
* @see #setJaxbContextProperties(Map)
|
||||
* @see #setMarshallerProperties(Map)
|
||||
* @see #setUnmarshallerProperties(Map)
|
||||
* @see #setSchema(Resource)
|
||||
* @see #setSchemas(Resource[])
|
||||
* @see #setMarshallerListener(javax.xml.bind.Marshaller.Listener)
|
||||
* @see #setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener)
|
||||
* @see #setAdapters(XmlAdapter[])
|
||||
* @see #setContextPath
|
||||
* @see #setClassesToBeBound
|
||||
* @see #setJaxbContextProperties
|
||||
* @see #setMarshallerProperties
|
||||
* @see #setUnmarshallerProperties
|
||||
* @see #setSchema
|
||||
* @see #setSchemas
|
||||
* @see #setMarshallerListener
|
||||
* @see #setUnmarshallerListener
|
||||
* @see #setAdapters
|
||||
*/
|
||||
public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, GenericMarshaller, GenericUnmarshaller,
|
||||
BeanClassLoaderAware, InitializingBean {
|
||||
|
||||
private static final String CID = "cid:";
|
||||
|
||||
private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
|
||||
@Override
|
||||
public InputSource resolveEntity(String publicId, String systemId) {
|
||||
return new InputSource(new StringReader(""));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Logger available to subclasses */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
@@ -226,8 +233,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
* Set the packages to search for classes with JAXB2 annotations in the classpath.
|
||||
* This is using a Spring-bases search and therefore analogous to Spring's component-scan
|
||||
* feature ({@link org.springframework.context.annotation.ClassPathBeanDefinitionScanner}).
|
||||
* <p>Setting either this property, {@link #setContextPath "contextPath"}
|
||||
* or {@link #setClassesToBeBound "classesToBeBound"} is required.
|
||||
* <p>Setting either this property, {@link #setContextPath "contextPath"} or
|
||||
* {@link #setClassesToBeBound "classesToBeBound"} is required.
|
||||
*/
|
||||
public void setPackagesToScan(String... packagesToScan) {
|
||||
this.packagesToScan = packagesToScan;
|
||||
@@ -249,8 +256,9 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the JAXB {@code Marshaller} properties. These properties will be set on the
|
||||
* underlying JAXB {@code Marshaller}, and allow for features such as indentation.
|
||||
* Set the JAXB {@code Marshaller} properties.
|
||||
* <p>These properties will be set on the underlying JAXB {@code Marshaller},
|
||||
* and allow for features such as indentation.
|
||||
* @param properties the properties
|
||||
* @see javax.xml.bind.Marshaller#setProperty(String, Object)
|
||||
* @see javax.xml.bind.Marshaller#JAXB_ENCODING
|
||||
@@ -263,8 +271,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the JAXB {@code Unmarshaller} properties. These properties will be set on the
|
||||
* underlying JAXB {@code Unmarshaller}.
|
||||
* Set the JAXB {@code Unmarshaller} properties.
|
||||
* <p>These properties will be set on the underlying JAXB {@code Unmarshaller}.
|
||||
* @param properties the properties
|
||||
* @see javax.xml.bind.Unmarshaller#setProperty(String, Object)
|
||||
*/
|
||||
@@ -296,7 +304,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
|
||||
/**
|
||||
* Specify the {@code XmlAdapter}s to be registered with the JAXB {@code Marshaller}
|
||||
* and {@code Unmarshaller}
|
||||
* and {@code Unmarshaller}.
|
||||
*/
|
||||
public void setAdapters(XmlAdapter<?, ?>... adapters) {
|
||||
this.adapters = adapters;
|
||||
@@ -317,7 +325,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the schema language. Default is the W3C XML Schema: {@code http://www.w3.org/2001/XMLSchema"}.
|
||||
* Set the schema language.
|
||||
* Default is the W3C XML Schema: {@code http://www.w3.org/2001/XMLSchema"}.
|
||||
* @see XMLConstants#W3C_XML_SCHEMA_NS_URI
|
||||
* @see XMLConstants#RELAXNG_NS_URI
|
||||
*/
|
||||
@@ -353,10 +362,11 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether the {@link #supports(Class)} returns {@code true} for the {@link JAXBElement} class.
|
||||
* <p>Default is {@code false}, meaning that {@code supports(Class)} always returns {@code false} for
|
||||
* {@code JAXBElement} classes (though {@link #supports(Type)} can return {@code true}, since it can
|
||||
* obtain the type parameters of {@code JAXBElement}).
|
||||
* Specify whether the {@link #supports(Class)} returns {@code true} for the
|
||||
* {@link JAXBElement} class.
|
||||
* <p>Default is {@code false}, meaning that {@code supports(Class)} always returns
|
||||
* {@code false} for {@code JAXBElement} classes (though {@link #supports(Type)} can
|
||||
* return {@code true}, since it can obtain the type parameters of {@code JAXBElement}).
|
||||
* <p>This property is typically enabled in combination with usage of classes like
|
||||
* {@link org.springframework.web.servlet.view.xml.MarshallingView MarshallingView},
|
||||
* since the {@code ModelAndView} does not offer type parameter information at runtime.
|
||||
@@ -412,8 +422,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
* {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or
|
||||
* {@link StreamSource}. It has no effect for {@link DOMSource} or {@link StAXSource}
|
||||
* instances.
|
||||
* <p><strong>Note:</strong> setting this option to {@code true} also
|
||||
* automatically sets {@link #setSupportDtd} to {@code true}.
|
||||
* <p><strong>Note:</strong> setting this option to {@code true} also automatically
|
||||
* sets {@link #setSupportDtd} to {@code true}.
|
||||
*/
|
||||
public void setProcessExternalEntities(boolean processExternalEntities) {
|
||||
this.processExternalEntities = processExternalEntities;
|
||||
@@ -685,6 +695,21 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a newly created JAXB marshaller.
|
||||
* <p>Note: JAXB marshallers are not necessarily thread-safe.
|
||||
*/
|
||||
protected Marshaller createMarshaller() {
|
||||
try {
|
||||
Marshaller marshaller = getJaxbContext().createMarshaller();
|
||||
initJaxbMarshaller(marshaller);
|
||||
return marshaller;
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw convertJaxbException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void marshalStaxResult(Marshaller jaxbMarshaller, Object graph, Result staxResult) throws JAXBException {
|
||||
XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(staxResult);
|
||||
if (streamWriter != null) {
|
||||
@@ -702,26 +727,14 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a newly created JAXB marshaller. JAXB marshallers are not necessarily thread safe.
|
||||
*/
|
||||
protected Marshaller createMarshaller() {
|
||||
try {
|
||||
Marshaller marshaller = getJaxbContext().createMarshaller();
|
||||
initJaxbMarshaller(marshaller);
|
||||
return marshaller;
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw convertJaxbException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.
|
||||
* Gets called after creation of JAXB {@code Marshaller}, and after the respective properties have been set.
|
||||
* <p>The default implementation sets the {@link #setMarshallerProperties(Map) defined properties}, the {@link
|
||||
* #setValidationEventHandler(ValidationEventHandler) validation event handler}, the {@link #setSchemas(Resource[])
|
||||
* schemas}, {@link #setMarshallerListener(javax.xml.bind.Marshaller.Listener) listener}, and
|
||||
* {@link #setAdapters(XmlAdapter[]) adapters}.
|
||||
* Template method that can be overridden by concrete JAXB marshallers
|
||||
* for custom initialization behavior. Gets called after creation of JAXB
|
||||
* {@code Marshaller}, and after the respective properties have been set.
|
||||
* <p>The default implementation sets the
|
||||
* {@link #setMarshallerProperties defined properties}, the
|
||||
* {@link #setValidationEventHandler validation event handler}, the
|
||||
* {@link #setSchemas schemas}, {@link #setMarshallerListener listener},
|
||||
* and {@link #setAdapters adapters}.
|
||||
*/
|
||||
protected void initJaxbMarshaller(Marshaller marshaller) throws JAXBException {
|
||||
if (this.marshallerProperties != null) {
|
||||
@@ -774,9 +787,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
catch (NullPointerException ex) {
|
||||
if (!isSupportDtd()) {
|
||||
throw new UnmarshallingFailureException("NPE while unmarshalling. " +
|
||||
"This can happen on JDK 1.6 due to the presence of DTD " +
|
||||
"declarations, which are disabled.", ex);
|
||||
throw new UnmarshallingFailureException("NPE while unmarshalling: " +
|
||||
"This can happen due to the presence of DTD declarations which are disabled.", ex);
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
@@ -785,6 +797,21 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a newly created JAXB unmarshaller.
|
||||
* <p>Note: JAXB unmarshallers are not necessarily thread-safe.
|
||||
*/
|
||||
protected Unmarshaller createUnmarshaller() {
|
||||
try {
|
||||
Unmarshaller unmarshaller = getJaxbContext().createUnmarshaller();
|
||||
initJaxbUnmarshaller(unmarshaller);
|
||||
return unmarshaller;
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw convertJaxbException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSource) throws JAXBException {
|
||||
XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource);
|
||||
if (streamReader != null) {
|
||||
@@ -850,27 +877,14 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a newly created JAXB unmarshaller.
|
||||
* Note: JAXB unmarshallers are not necessarily thread-safe.
|
||||
*/
|
||||
protected Unmarshaller createUnmarshaller() {
|
||||
try {
|
||||
Unmarshaller unmarshaller = getJaxbContext().createUnmarshaller();
|
||||
initJaxbUnmarshaller(unmarshaller);
|
||||
return unmarshaller;
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw convertJaxbException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.
|
||||
* Gets called after creation of JAXB {@code Marshaller}, and after the respective properties have been set.
|
||||
* <p>The default implementation sets the {@link #setUnmarshallerProperties(Map) defined properties}, the {@link
|
||||
* #setValidationEventHandler(ValidationEventHandler) validation event handler}, the {@link #setSchemas(Resource[])
|
||||
* schemas}, {@link #setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener) listener}, and
|
||||
* {@link #setAdapters(XmlAdapter[]) adapters}.
|
||||
* Template method that can be overridden by concrete JAXB marshallers
|
||||
* for custom initialization behavior. Gets called after creation of JAXB
|
||||
* {@code Marshaller}, and after the respective properties have been set.
|
||||
* <p>The default implementation sets the
|
||||
* {@link #setUnmarshallerProperties defined properties}, the
|
||||
* {@link #setValidationEventHandler validation event handler}, the
|
||||
* {@link #setSchemas schemas}, {@link #setUnmarshallerListener listener},
|
||||
* and {@link #setAdapters adapters}.
|
||||
*/
|
||||
protected void initJaxbUnmarshaller(Unmarshaller unmarshaller) throws JAXBException {
|
||||
if (this.unmarshallerProperties != null) {
|
||||
@@ -895,8 +909,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given {@code JAXBException} to an appropriate exception from the
|
||||
* {@code org.springframework.oxm} hierarchy.
|
||||
* Convert the given {@code JAXBException} to an appropriate exception
|
||||
* from the {@code org.springframework.oxm} hierarchy.
|
||||
* @param ex {@code JAXBException} that occurred
|
||||
* @return the corresponding {@code XmlMappingException}
|
||||
*/
|
||||
@@ -1053,12 +1067,4 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
|
||||
@Override
|
||||
public InputSource resolveEntity(String publicId, String systemId) {
|
||||
return new InputSource(new StringReader(""));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ import org.springframework.util.StringUtils;
|
||||
* <li>{@link #set(String, String)} sets the header value to a single string value</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Note that {@code HttpHeaders} generally treats header names in a case-insensitive manner.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Sebastien Deleuze
|
||||
* @author Brian Clozel
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -34,24 +34,20 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* <p>By default a newly created {@code CorsConfiguration} does not permit any
|
||||
* cross-origin requests and must be configured explicitly to indicate what
|
||||
* should be allowed.
|
||||
*
|
||||
* <p>Use {@link #applyPermitDefaultValues()} to flip the initialization model
|
||||
* to start with open defaults that permit all cross-origin requests for GET,
|
||||
* HEAD, and POST requests.
|
||||
* should be allowed. Use {@link #applyPermitDefaultValues()} to flip the
|
||||
* initialization model to start with open defaults that permit all cross-origin
|
||||
* requests for GET, HEAD, and POST requests.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 4.2
|
||||
* @see <a href="https://www.w3.org/TR/cors/">CORS W3C recommendation</a>
|
||||
* @see <a href="https://www.w3.org/TR/cors/">CORS spec</a>
|
||||
*/
|
||||
public class CorsConfiguration {
|
||||
|
||||
/**
|
||||
* Wildcard representing <em>all</em> origins, methods, or headers.
|
||||
*/
|
||||
/** Wildcard representing <em>all</em> origins, methods, or headers. */
|
||||
public static final String ALL = "*";
|
||||
|
||||
private static final List<HttpMethod> DEFAULT_METHODS;
|
||||
@@ -304,23 +300,21 @@ public class CorsConfiguration {
|
||||
return this.maxAge;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* By default a newly created {@code CorsConfiguration} does not permit any
|
||||
* cross-origin requests and must be configured explicitly to indicate what
|
||||
* should be allowed.
|
||||
*
|
||||
* <p>Use this method to flip the initialization model to start with open
|
||||
* defaults that permit all cross-origin requests for GET, HEAD, and POST
|
||||
* requests. Note however that this method will not override any existing
|
||||
* values already set.
|
||||
*
|
||||
* <p>The following defaults are applied if not already set:
|
||||
* <ul>
|
||||
* <li>Allow all origins, i.e. {@code "*"}.</li>
|
||||
* <li>Allow "simple" methods {@code GET}, {@code HEAD} and {@code POST}.</li>
|
||||
* <li>Allow all headers.</li>
|
||||
* <li>Allow credentials.</li>
|
||||
* <li>Set max age to 1800 seconds (30 minutes).</li>
|
||||
* <li>Allow all origins.</li>
|
||||
* <li>Allow "simple" methods {@code GET}, {@code HEAD} and {@code POST}.</li>
|
||||
* <li>Allow all headers.</li>
|
||||
* <li>Set max age to 1800 seconds (30 minutes).</li>
|
||||
* </ul>
|
||||
*/
|
||||
public CorsConfiguration applyPermitDefaultValues() {
|
||||
|
||||
@@ -145,16 +145,8 @@ import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
|
||||
import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests loading actual MVC namespace configuration.
|
||||
@@ -181,7 +173,7 @@ public class MvcNamespaceTests {
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() throws Exception {
|
||||
TestMockServletContext servletContext = new TestMockServletContext();
|
||||
appContext = new XmlWebApplicationContext();
|
||||
appContext.setServletContext(servletContext);
|
||||
|
||||
Reference in New Issue
Block a user