Compare commits

..

1 Commits

Author SHA1 Message Date
Spring Builds 850cb6c4c9 Release v5.3.12 2021-10-21 05:44:20 +00:00
55 changed files with 362 additions and 872 deletions
+7 -7
View File
@@ -28,8 +28,8 @@ configure(allprojects) { project ->
dependencyManagement {
imports {
mavenBom "com.fasterxml.jackson:jackson-bom:2.12.5"
mavenBom "io.netty:netty-bom:4.1.70.Final"
mavenBom "io.projectreactor:reactor-bom:2020.0.13"
mavenBom "io.netty:netty-bom:4.1.69.Final"
mavenBom "io.projectreactor:reactor-bom:2020.0.12"
mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR10"
mavenBom "io.rsocket:rsocket-bom:1.1.1"
mavenBom "org.eclipse.jetty:jetty-bom:9.4.44.v20210927"
@@ -128,14 +128,14 @@ configure(allprojects) { project ->
dependency "org.webjars:webjars-locator-core:0.48"
dependency "org.webjars:underscorejs:1.8.3"
dependencySet(group: 'org.apache.tomcat', version: '9.0.54') {
dependencySet(group: 'org.apache.tomcat', version: '9.0.53') {
entry 'tomcat-util'
entry('tomcat-websocket') {
exclude group: "org.apache.tomcat", name: "tomcat-websocket-api"
exclude group: "org.apache.tomcat", name: "tomcat-servlet-api"
}
}
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.54') {
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.53') {
entry 'tomcat-embed-core'
entry 'tomcat-embed-websocket'
}
@@ -192,7 +192,7 @@ configure(allprojects) { project ->
dependency "org.hamcrest:hamcrest:2.1"
dependency "org.awaitility:awaitility:3.1.6"
dependency "org.assertj:assertj-core:3.21.0"
dependencySet(group: 'org.xmlunit', version: '2.8.3') {
dependencySet(group: 'org.xmlunit', version: '2.8.2') {
entry 'xmlunit-assertj'
entry('xmlunit-matchers') {
exclude group: "org.hamcrest", name: "hamcrest-core"
@@ -206,10 +206,10 @@ configure(allprojects) { project ->
}
dependency "io.mockk:mockk:1.12.0"
dependency("net.sourceforge.htmlunit:htmlunit:2.54.0") {
dependency("net.sourceforge.htmlunit:htmlunit:2.53.0") {
exclude group: "commons-logging", name: "commons-logging"
}
dependency("org.seleniumhq.selenium:htmlunit-driver:2.54.0") {
dependency("org.seleniumhq.selenium:htmlunit-driver:2.53.0") {
exclude group: "commons-logging", name: "commons-logging"
}
dependency("org.seleniumhq.selenium:selenium-java:3.141.59") {
+1 -1
View File
@@ -1,4 +1,4 @@
version=5.3.13
version=5.3.12
org.gradle.jvmargs=-Xmx1536M
org.gradle.caching=true
org.gradle.parallel=true
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -422,13 +422,10 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
}
if (editor == null) {
// Find editor for superclass or interface.
for (Map.Entry<Class<?>, PropertyEditor> entry : this.customEditors.entrySet()) {
if (editor != null) {
break;
}
Class<?> key = entry.getKey();
for (Iterator<Class<?>> it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
Class<?> key = it.next();
if (key.isAssignableFrom(requiredType)) {
editor = entry.getValue();
editor = this.customEditors.get(key);
// Cache editor for search type, to avoid the overhead
// of repeated assignable-from checks.
if (this.customEditorCache == null) {
@@ -459,7 +459,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
return metadata;
}
private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
private InjectionMetadata buildAutowiringMetadata(final Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, this.autowiredAnnotationTypes)) {
return InjectionMetadata.EMPTY;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 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.
@@ -570,7 +570,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
if (this.dataSource != null) {
mergedProps.putIfAbsent(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
}
// Determine scheduler name across local settings and Quartz properties...
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.scheduling.quartz;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
@@ -31,7 +30,6 @@ import org.quartz.SchedulerContext;
import org.quartz.SchedulerFactory;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.SchedulerRepository;
import org.quartz.impl.jdbcjobstore.JobStoreTX;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -42,8 +40,6 @@ import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.testfixture.EnabledForTestGroups;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -61,10 +57,10 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
* @author Sam Brannen
* @since 20.02.2004
*/
class QuartzSupportTests {
public class QuartzSupportTests {
@Test
void schedulerFactoryBeanWithApplicationContext() throws Exception {
public void schedulerFactoryBeanWithApplicationContext() throws Exception {
TestBean tb = new TestBean("tb", 99);
StaticApplicationContext ac = new StaticApplicationContext();
@@ -101,7 +97,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithTaskExecutor() throws Exception {
public void schedulerWithTaskExecutor() throws Exception {
CountingTaskExecutor taskExecutor = new CountingTaskExecutor();
DummyJob.count = 0;
@@ -134,7 +130,7 @@ class QuartzSupportTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
void jobDetailWithRunnableInsteadOfJob() {
public void jobDetailWithRunnableInsteadOfJob() {
JobDetailImpl jobDetail = new JobDetailImpl();
assertThatIllegalArgumentException().isThrownBy(() ->
jobDetail.setJobClass((Class) DummyRunnable.class));
@@ -142,7 +138,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithQuartzJobBean() throws Exception {
public void schedulerWithQuartzJobBean() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -175,7 +171,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactory() throws Exception {
public void schedulerWithSpringBeanJobFactory() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -210,7 +206,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception {
public void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -246,7 +242,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
DummyJobBean.param = 0;
DummyJobBean.count = 0;
@@ -280,7 +276,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws Exception {
public void schedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -298,7 +294,7 @@ class QuartzSupportTests {
}
@Test // SPR-772
void multipleSchedulers() throws Exception {
public void multipleSchedulers() throws Exception {
try (ClassPathXmlApplicationContext ctx = context("multipleSchedulers.xml")) {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
@@ -309,7 +305,7 @@ class QuartzSupportTests {
}
@Test // SPR-16884
void multipleSchedulersWithQuartzProperties() throws Exception {
public void multipleSchedulersWithQuartzProperties() throws Exception {
try (ClassPathXmlApplicationContext ctx = context("multipleSchedulersWithQuartzProperties.xml")) {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
@@ -321,13 +317,12 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void twoAnonymousMethodInvokingJobDetailFactoryBeans() throws Exception {
public void twoAnonymousMethodInvokingJobDetailFactoryBeans() throws Exception {
Thread.sleep(3000);
try (ClassPathXmlApplicationContext ctx = context("multipleAnonymousMethodInvokingJobDetailFB.xml")) {
QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");
Thread.sleep(400);
assertThat(exportService.getImportCount()).as("doImport called exportService").isEqualTo(0);
assertThat(exportService.getExportCount()).as("doExport not called on exportService").isEqualTo(2);
assertThat(importService.getImportCount()).as("doImport not called on importService").isEqualTo(2);
@@ -337,13 +332,12 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerAccessorBean() throws Exception {
public void schedulerAccessorBean() throws Exception {
Thread.sleep(3000);
try (ClassPathXmlApplicationContext ctx = context("schedulerAccessorBean.xml")) {
QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");
Thread.sleep(400);
assertThat(exportService.getImportCount()).as("doImport called exportService").isEqualTo(0);
assertThat(exportService.getExportCount()).as("doExport not called on exportService").isEqualTo(2);
assertThat(importService.getImportCount()).as("doImport not called on importService").isEqualTo(2);
@@ -353,7 +347,7 @@ class QuartzSupportTests {
@Test
@SuppressWarnings("resource")
void schedulerAutoStartsOnContextRefreshedEventByDefault() throws Exception {
public void schedulerAutoStartsOnContextRefreshedEventByDefault() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("scheduler", new RootBeanDefinition(SchedulerFactoryBean.class));
Scheduler bean = context.getBean("scheduler", Scheduler.class);
@@ -364,7 +358,7 @@ class QuartzSupportTests {
@Test
@SuppressWarnings("resource")
void schedulerAutoStartupFalse() throws Exception {
public void schedulerAutoStartupFalse() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class)
.addPropertyValue("autoStartup", false).getBeanDefinition();
@@ -376,7 +370,7 @@ class QuartzSupportTests {
}
@Test
void schedulerRepositoryExposure() throws Exception {
public void schedulerRepositoryExposure() throws Exception {
try (ClassPathXmlApplicationContext ctx = context("schedulerRepositoryExposure.xml")) {
assertThat(ctx.getBean("scheduler")).isSameAs(SchedulerRepository.getInstance().lookup("myScheduler"));
}
@@ -387,7 +381,7 @@ class QuartzSupportTests {
* TODO: Against Quartz 2.2, this test's job doesn't actually execute anymore...
*/
@Test
void schedulerWithHsqlDataSource() throws Exception {
public void schedulerWithHsqlDataSource() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -402,36 +396,12 @@ class QuartzSupportTests {
}
}
@Test
@SuppressWarnings("resource")
void schedulerFactoryBeanWithCustomJobStore() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
String dbName = "mydb";
EmbeddedDatabase database = new EmbeddedDatabaseBuilder().setName(dbName).build();
Properties properties = new Properties();
properties.setProperty("org.quartz.jobStore.class", JobStoreTX.class.getName());
properties.setProperty("org.quartz.jobStore.dataSource", dbName);
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class)
.addPropertyValue("autoStartup", false)
.addPropertyValue("dataSource", database)
.addPropertyValue("quartzProperties", properties)
.getBeanDefinition();
context.registerBeanDefinition("scheduler", beanDefinition);
Scheduler scheduler = context.getBean(Scheduler.class);
assertThat(scheduler.getMetaData().getJobStoreClass()).isEqualTo(JobStoreTX.class);
}
private ClassPathXmlApplicationContext context(String path) {
return new ClassPathXmlApplicationContext(path, getClass());
}
private static class CountingTaskExecutor implements TaskExecutor {
public static class CountingTaskExecutor implements TaskExecutor {
private int count;
@@ -443,14 +413,12 @@ class QuartzSupportTests {
}
private static class DummyJob implements Job {
public static class DummyJob implements Job {
private static int param;
private static int count;
@SuppressWarnings("unused")
// Must be public
public void setParam(int value) {
if (param > 0) {
throw new IllegalStateException("Param already set");
@@ -465,13 +433,12 @@ class QuartzSupportTests {
}
private static class DummyJobBean extends QuartzJobBean {
public static class DummyJobBean extends QuartzJobBean {
private static int param;
private static int count;
@SuppressWarnings("unused")
public void setParam(int value) {
if (param > 0) {
throw new IllegalStateException("Param already set");
@@ -486,7 +453,7 @@ class QuartzSupportTests {
}
private static class DummyRunnable implements Runnable {
public static class DummyRunnable implements Runnable {
@Override
public void run() {
@@ -19,7 +19,7 @@
<property name="targetMethod" value="doExport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -30,7 +30,7 @@
<property name="targetMethod" value="doImport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -21,7 +21,7 @@
<property name="targetMethod" value="doExport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -32,7 +32,7 @@
<property name="targetMethod" value="doImport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -343,7 +343,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
private InjectionMetadata findResourceMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
@@ -363,7 +363,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
return metadata;
}
private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
private InjectionMetadata buildResourceMetadata(final Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, resourceAnnotationTypes)) {
return InjectionMetadata.EMPTY;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 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,10 +16,13 @@
package org.springframework.context.annotation;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
@@ -30,7 +33,12 @@ import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AspectJTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -65,7 +73,7 @@ class ComponentScanAnnotationParser {
}
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, String declaringClass) {
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, final String declaringClass) {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(this.registry,
componentScan.getBoolean("useDefaultFilters"), this.environment, this.resourceLoader);
@@ -85,17 +93,13 @@ class ComponentScanAnnotationParser {
scanner.setResourcePattern(componentScan.getString("resourcePattern"));
for (AnnotationAttributes includeFilterAttributes : componentScan.getAnnotationArray("includeFilters")) {
List<TypeFilter> typeFilters = TypeFilterUtils.createTypeFiltersFor(includeFilterAttributes, this.environment,
this.resourceLoader, this.registry);
for (TypeFilter typeFilter : typeFilters) {
for (AnnotationAttributes filter : componentScan.getAnnotationArray("includeFilters")) {
for (TypeFilter typeFilter : typeFiltersFor(filter)) {
scanner.addIncludeFilter(typeFilter);
}
}
for (AnnotationAttributes excludeFilterAttributes : componentScan.getAnnotationArray("excludeFilters")) {
List<TypeFilter> typeFilters = TypeFilterUtils.createTypeFiltersFor(excludeFilterAttributes, this.environment,
this.resourceLoader, this.registry);
for (TypeFilter typeFilter : typeFilters) {
for (AnnotationAttributes filter : componentScan.getAnnotationArray("excludeFilters")) {
for (TypeFilter typeFilter : typeFiltersFor(filter)) {
scanner.addExcludeFilter(typeFilter);
}
}
@@ -128,4 +132,49 @@ class ComponentScanAnnotationParser {
return scanner.doScan(StringUtils.toStringArray(basePackages));
}
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
List<TypeFilter> typeFilters = new ArrayList<>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getClassArray("classes")) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"@ComponentScan ANNOTATION type filter requires an annotation type");
@SuppressWarnings("unchecked")
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
typeFilters.add(new AnnotationTypeFilter(annotationType));
break;
case ASSIGNABLE_TYPE:
typeFilters.add(new AssignableTypeFilter(filterClass));
break;
case CUSTOM:
Assert.isAssignable(TypeFilter.class, filterClass,
"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
TypeFilter filter = ParserStrategyUtils.instantiateClass(filterClass, TypeFilter.class,
this.environment, this.resourceLoader, this.registry);
typeFilters.add(filter);
break;
default:
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
}
}
for (String expression : filterAttributes.getStringArray("pattern")) {
switch (filterType) {
case ASPECTJ:
typeFilters.add(new AspectJTypeFilter(expression, this.resourceLoader.getClassLoader()));
break;
case REGEX:
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
break;
default:
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
}
}
return typeFilters;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 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.
@@ -453,8 +453,8 @@ class ConfigurationClassEnhancer {
* instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing,
* it will not be proxied. This too is aligned with the way XML configuration works.
*/
private Object enhanceFactoryBean(Object factoryBean, Class<?> exposedType,
ConfigurableBeanFactory beanFactory, String beanName) {
private Object enhanceFactoryBean(final Object factoryBean, Class<?> exposedType,
final ConfigurableBeanFactory beanFactory, final String beanName) {
try {
Class<?> clazz = factoryBean.getClass();
@@ -489,8 +489,8 @@ class ConfigurationClassEnhancer {
return createCglibProxyForFactoryBean(factoryBean, beanFactory, beanName);
}
private Object createInterfaceProxyForFactoryBean(Object factoryBean, Class<?> interfaceType,
ConfigurableBeanFactory beanFactory, String beanName) {
private Object createInterfaceProxyForFactoryBean(final Object factoryBean, Class<?> interfaceType,
final ConfigurableBeanFactory beanFactory, final String beanName) {
return Proxy.newProxyInstance(
factoryBean.getClass().getClassLoader(), new Class<?>[] {interfaceType},
@@ -502,8 +502,8 @@ class ConfigurationClassEnhancer {
});
}
private Object createCglibProxyForFactoryBean(Object factoryBean,
ConfigurableBeanFactory beanFactory, String beanName) {
private Object createCglibProxyForFactoryBean(final Object factoryBean,
final ConfigurableBeanFactory beanFactory, final String beanName) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(factoryBean.getClass());
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2013 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.
@@ -47,11 +47,6 @@ import java.lang.annotation.Target;
* or {@link javax.inject.Inject}: In that context, it leads to the creation of a
* lazy-resolution proxy for all affected dependencies, as an alternative to using
* {@link org.springframework.beans.factory.ObjectFactory} or {@link javax.inject.Provider}.
* Please note that such a lazy-resolution proxy will always be injected; if the target
* dependency does not exist, you will only be able to find out through an exception on
* invocation. As a consequence, such an injection point results in unintuitive behavior
* for optional dependencies. For a programmatic equivalent, allowing for lazy references
* with more sophistication, consider {@link org.springframework.beans.factory.ObjectProvider}.
*
* @author Chris Beams
* @author Juergen Hoeller
@@ -1,119 +0,0 @@
/*
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.annotation;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AspectJTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.util.Assert;
/**
* Collection of utilities for working with {@link ComponentScan @ComponentScan}
* {@linkplain ComponentScan.Filter type filters}.
*
* @author Chris Beams
* @author Juergen Hoeller
* @author Sam Brannen
* @since 5.3.13
* @see ComponentScan.Filter
* @see org.springframework.core.type.filter.TypeFilter
*/
public abstract class TypeFilterUtils {
/**
* Create {@linkplain TypeFilter type filters} from the supplied
* {@link AnnotationAttributes}, such as those sourced from
* {@link ComponentScan#includeFilters()} or {@link ComponentScan#excludeFilters()}.
* <p>Each {@link TypeFilter} will be instantiated using an appropriate
* constructor, with {@code BeanClassLoaderAware}, {@code BeanFactoryAware},
* {@code EnvironmentAware}, and {@code ResourceLoaderAware} contracts
* invoked if they are implemented by the type filter.
* @param filterAttributes {@code AnnotationAttributes} for a
* {@link ComponentScan.Filter @Filter} declaration
* @param environment the {@code Environment} to make available to filters
* @param resourceLoader the {@code ResourceLoader} to make available to filters
* @param registry the {@code BeanDefinitionRegistry} to make available to filters
* as a {@link org.springframework.beans.factory.BeanFactory} if applicable
* @return a list of instantiated and configured type filters
* @see TypeFilter
* @see AnnotationTypeFilter
* @see AssignableTypeFilter
* @see AspectJTypeFilter
* @see RegexPatternTypeFilter
* @see org.springframework.beans.factory.BeanClassLoaderAware
* @see org.springframework.beans.factory.BeanFactoryAware
* @see org.springframework.context.EnvironmentAware
* @see org.springframework.context.ResourceLoaderAware
*/
public static List<TypeFilter> createTypeFiltersFor(AnnotationAttributes filterAttributes, Environment environment,
ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {
List<TypeFilter> typeFilters = new ArrayList<>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getClassArray("classes")) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"@ComponentScan ANNOTATION type filter requires an annotation type");
@SuppressWarnings("unchecked")
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
typeFilters.add(new AnnotationTypeFilter(annotationType));
break;
case ASSIGNABLE_TYPE:
typeFilters.add(new AssignableTypeFilter(filterClass));
break;
case CUSTOM:
Assert.isAssignable(TypeFilter.class, filterClass,
"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
TypeFilter filter = ParserStrategyUtils.instantiateClass(filterClass, TypeFilter.class,
environment, resourceLoader, registry);
typeFilters.add(filter);
break;
default:
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
}
}
for (String expression : filterAttributes.getStringArray("pattern")) {
switch (filterType) {
case ASPECTJ:
typeFilters.add(new AspectJTypeFilter(expression, resourceLoader.getClassLoader()));
break;
case REGEX:
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
break;
default:
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
}
}
return typeFilters;
}
}
@@ -75,7 +75,7 @@ public abstract class CachedExpressionEvaluator {
/**
* Return the {@link Expression} for the specified SpEL value
* <p>{@link #parseExpression(String) Parse the expression} if it hasn't been already.
* <p>Parse the expression if it hasn't been already.
* @param cache the cache to use
* @param elementKey the element on which the expression is defined
* @param expression the expression to parse
@@ -86,21 +86,12 @@ public abstract class CachedExpressionEvaluator {
ExpressionKey expressionKey = createKey(elementKey, expression);
Expression expr = cache.get(expressionKey);
if (expr == null) {
expr = parseExpression(expression);
expr = getParser().parseExpression(expression);
cache.put(expressionKey, expr);
}
return expr;
}
/**
* Parse the specified {@code expression}.
* @param expression the expression to parse
* @since 5.3.13
*/
protected Expression parseExpression(String expression) {
return getParser().parseExpression(expression);
}
private ExpressionKey createKey(AnnotatedElementKey elementKey, String expression) {
return new ExpressionKey(elementKey, expression);
}
@@ -107,7 +107,7 @@ public final class CandidateComponentsIndexLoader {
result.add(properties);
}
if (logger.isDebugEnabled()) {
logger.debug("Loaded " + result.size() + " index(es)");
logger.debug("Loaded " + result.size() + "] index(es)");
}
int totalCount = result.stream().mapToInt(Properties::size).sum();
return (totalCount > 0 ? new CandidateComponentsIndex(result) : null);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -67,17 +67,6 @@ public class MapAccessorTests {
assertThat(ex.getValue(sec,mapGetter)).isEqualTo("bar");
assertThat(SpelCompiler.compile(ex)).isTrue();
assertThat(ex.getValue(sec,mapGetter)).isEqualTo("bar");
// basic isWritable
ex = sep.parseExpression("foo");
assertThat(ex.isWritable(sec,testMap)).isTrue();
// basic write
ex = sep.parseExpression("foo2");
ex.setValue(sec, testMap, "bar2");
assertThat(ex.getValue(sec,testMap)).isEqualTo("bar2");
assertThat(SpelCompiler.compile(ex)).isTrue();
assertThat(ex.getValue(sec,testMap)).isEqualTo("bar2");
}
public static class MapGetter {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -321,6 +321,28 @@ public class FormattingConversionServiceTests {
TypeDescriptor.valueOf(String.class));
}
@Test
public void registerDefaultValueViaFormatter() {
registerDefaultValue(Date.class, new Date());
}
private <T> void registerDefaultValue(Class<T> clazz, final T defaultValue) {
formattingService.addFormatterForFieldType(clazz, new Formatter<T>() {
@Override
public T parse(String text, Locale locale) {
return defaultValue;
}
@Override
public String print(T t, Locale locale) {
return defaultValue.toString();
}
@Override
public String toString() {
return defaultValue.toString();
}
});
}
@Test
public void introspectedFormatter() {
formattingService.addFormatter(new NumberStyleFormatter("#,#00.0#"));
@@ -37,7 +37,7 @@ import org.springframework.util.ObjectUtils;
/**
* Contextual descriptor about a type to convert from or to.
* <p>Capable of representing arrays and generic collection types.
* Capable of representing arrays and generic collection types.
*
* @author Keith Donald
* @author Andy Clement
@@ -345,9 +345,9 @@ public class TypeDescriptor implements Serializable {
* from the provided collection or array element.
* <p>Narrows the {@link #getElementTypeDescriptor() elementType} property to the class
* of the provided collection or array element. For example, if this describes a
* {@code java.util.List<java.lang.Number>} and the element argument is a
* {@code java.util.List&lt;java.lang.Number&lt;} and the element argument is an
* {@code java.lang.Integer}, the returned TypeDescriptor will be {@code java.lang.Integer}.
* If this describes a {@code java.util.List<?>} and the element argument is a
* If this describes a {@code java.util.List&lt;?&gt;} and the element argument is an
* {@code java.lang.Integer}, the returned TypeDescriptor will be {@code java.lang.Integer}
* as well.
* <p>Annotation and nested type context will be preserved in the narrowed
@@ -388,9 +388,9 @@ public class TypeDescriptor implements Serializable {
* from the provided map key.
* <p>Narrows the {@link #getMapKeyTypeDescriptor() mapKeyType} property
* to the class of the provided map key. For example, if this describes a
* {@code java.util.Map<java.lang.Number, java.lang.String>} and the key
* {@code java.util.Map&lt;java.lang.Number, java.lang.String&lt;} and the key
* argument is a {@code java.lang.Integer}, the returned TypeDescriptor will be
* {@code java.lang.Integer}. If this describes a {@code java.util.Map<?, ?>}
* {@code java.lang.Integer}. If this describes a {@code java.util.Map&lt;?, ?&gt;}
* and the key argument is a {@code java.lang.Integer}, the returned
* TypeDescriptor will be {@code java.lang.Integer} as well.
* <p>Annotation and nested type context will be preserved in the narrowed
@@ -425,9 +425,9 @@ public class TypeDescriptor implements Serializable {
* from the provided map value.
* <p>Narrows the {@link #getMapValueTypeDescriptor() mapValueType} property
* to the class of the provided map value. For example, if this describes a
* {@code java.util.Map<java.lang.String, java.lang.Number>} and the value
* {@code java.util.Map&lt;java.lang.String, java.lang.Number&lt;} and the value
* argument is a {@code java.lang.Integer}, the returned TypeDescriptor will be
* {@code java.lang.Integer}. If this describes a {@code java.util.Map<?, ?>}
* {@code java.lang.Integer}. If this describes a {@code java.util.Map&lt;?, ?&gt;}
* and the value argument is a {@code java.lang.Integer}, the returned
* TypeDescriptor will be {@code java.lang.Integer} as well.
* <p>Annotation and nested type context will be preserved in the narrowed
@@ -36,9 +36,8 @@ import org.springframework.lang.Nullable;
public abstract class LogFormatUtils {
/**
* Convenience variant of {@link #formatValue(Object, int, boolean)} that
* limits the length of a log message to 100 characters and also replaces
* newline characters if {@code limitLength} is set to "true".
* Variant of {@link #formatValue(Object, int, boolean)} and a convenience
* method that truncates at 100 characters when {@code limitLength} is set.
* @param value the value to format
* @param limitLength whether to truncate the value at a length of 100
* @return the formatted value
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2017 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,7 +44,7 @@ public interface TypeConverter {
* Convert (or coerce) a value from one type to another, for example from a
* {@code boolean} to a {@code String}.
* <p>The {@link TypeDescriptor} parameters enable support for typed collections:
* A caller may prefer a {@code List<Integer>}, for example, rather than
* A caller may prefer a {@code List&lt;Integer&gt;}, for example, rather than
* simply any {@code List}.
* @param value the value to be converted
* @param sourceType a type descriptor that supplies extra information about the
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 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.
@@ -38,7 +38,6 @@ import org.springframework.util.MethodInvoker;
*
* @author Andy Clement
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.0
*/
public abstract class ReflectionHelper {
@@ -282,32 +281,25 @@ public abstract class ReflectionHelper {
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
conversionOccurred |= (argument != arguments[i]);
}
MethodParameter methodParam = MethodParameter.forExecutable(executable, varargsPosition);
// If the target is varargs and there is just one more argument, then convert it here.
if (varargsPosition == arguments.length - 1) {
Object argument = arguments[varargsPosition];
// If the target is varargs and there is just one more argument
// then convert it here
TypeDescriptor targetType = new TypeDescriptor(methodParam);
Object argument = arguments[varargsPosition];
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
// If the argument type is equal to the varargs element type, there is no need
// to convert it or wrap it in an array. For example, using StringToArrayConverter
// to convert a String containing a comma would result in the String being split
// and repackaged in an array when it should be used as-is.
if (!sourceType.equals(targetType.getElementTypeDescriptor())) {
arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetType);
}
// Three outcomes of the above if-block:
// 1) the input argument was correct type but not wrapped in an array, and nothing was done.
// 2) the input argument was already compatible (i.e., array of valid type), and nothing was done.
// 3) the input argument was the wrong type and got converted and wrapped in an array.
arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetType);
// Three outcomes of that previous line:
// 1) the input argument was already compatible (ie. array of valid type) and nothing was done
// 2) the input argument was correct type but not in an array so it was made into an array
// 3) the input argument was the wrong type and got converted and put into an array
if (argument != arguments[varargsPosition] &&
!isFirstEntryInArray(argument, arguments[varargsPosition])) {
conversionOccurred = true; // case 3
}
}
// Otherwise, convert remaining arguments to the varargs element type.
else {
// Convert remaining arguments to the varargs element type
TypeDescriptor targetType = new TypeDescriptor(methodParam).getElementTypeDescriptor();
Assert.state(targetType != null, "No element type");
for (int i = varargsPosition; i < arguments.length; i++) {
@@ -340,8 +332,8 @@ public abstract class ReflectionHelper {
}
/**
* Package up the arguments so that they correctly match what is expected in requiredParameterTypes.
* <p>For example, if requiredParameterTypes is {@code (int, String[])} because the second parameter
* Package up the arguments so that they correctly match what is expected in parameterTypes.
* For example, if parameterTypes is {@code (int, String[])} because the second parameter
* was declared {@code String...}, then if arguments is {@code [1,"a","b"]} then it must be
* repackaged as {@code [1,new String[]{"a","b"}]} in order to match the expected types.
* @param requiredParameterTypes the types of the parameters for the invocation
@@ -358,24 +350,23 @@ public abstract class ReflectionHelper {
requiredParameterTypes[parameterCount - 1] !=
(args[argumentCount - 1] != null ? args[argumentCount - 1].getClass() : null)) {
// Create an array for the leading arguments plus the varargs array argument.
int arraySize = 0; // zero size array if nothing to pass as the varargs parameter
if (argumentCount >= parameterCount) {
arraySize = argumentCount - (parameterCount - 1);
}
// Create an array for the varargs arguments
Object[] newArgs = new Object[parameterCount];
// Copy all leading arguments to the new array, omitting the varargs array argument.
System.arraycopy(args, 0, newArgs, 0, newArgs.length - 1);
// Now sort out the final argument, which is the varargs one. Before entering this method,
// the arguments should have been converted to the box form of the required type.
int varargsArraySize = 0; // zero size array if nothing to pass as the varargs parameter
if (argumentCount >= parameterCount) {
varargsArraySize = argumentCount - (parameterCount - 1);
}
Class<?> componentType = requiredParameterTypes[parameterCount - 1].getComponentType();
Object varargsArray = Array.newInstance(componentType, varargsArraySize);
for (int i = 0; i < varargsArraySize; i++) {
Array.set(varargsArray, i, args[parameterCount - 1 + i]);
Object repackagedArgs = Array.newInstance(componentType, arraySize);
for (int i = 0; i < arraySize; i++) {
Array.set(repackagedArgs, i, args[parameterCount - 1 + i]);
}
// Finally, add the varargs array to the new arguments array.
newArgs[newArgs.length - 1] = varargsArray;
newArgs[newArgs.length - 1] = repackagedArgs;
return newArgs;
}
return args;
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -46,7 +46,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*
* @author Andy Clement
* @author Phillip Webb
* @author Sam Brannen
*/
public class MethodInvocationTests extends AbstractExpressionTests {
@@ -234,54 +233,26 @@ public class MethodInvocationTests extends AbstractExpressionTests {
@Test
public void testVarargsInvocation01() {
// Calling 'public int aVarargsMethod(String... strings)' - returns number of arguments
evaluate("aVarargsMethod('a','b','c')", 3, Integer.class);
evaluate("aVarargsMethod('a')", 1, Integer.class);
// Calling 'public int aVarargsMethod(String... strings)'
//evaluate("aVarargsMethod('a','b','c')", 3, Integer.class);
//evaluate("aVarargsMethod('a')", 1, Integer.class);
evaluate("aVarargsMethod()", 0, Integer.class);
evaluate("aVarargsMethod(1,2,3)", 3, Integer.class); // all need converting to strings
evaluate("aVarargsMethod(1)", 1, Integer.class); // needs string conversion
evaluate("aVarargsMethod(1,'a',3.0d)", 3, Integer.class); // first and last need conversion
evaluate("aVarargsMethod(new String[]{'a','b','c'})", 3, Integer.class);
// evaluate("aVarargsMethod(new String[]{'a','b','c'})", 3, Integer.class);
}
@Test
public void testVarargsInvocation02() {
// Calling 'public int aVarargsMethod2(int i, String... strings)' - returns int + length_of_strings
// Calling 'public int aVarargsMethod2(int i, String... strings)' - returns int+length_of_strings
evaluate("aVarargsMethod2(5,'a','b','c')", 8, Integer.class);
evaluate("aVarargsMethod2(2,'a')", 3, Integer.class);
evaluate("aVarargsMethod2(4)", 4, Integer.class);
evaluate("aVarargsMethod2(8,2,3)", 10, Integer.class);
evaluate("aVarargsMethod2(9)", 9, Integer.class);
evaluate("aVarargsMethod2(2,'a',3.0d)", 4, Integer.class);
evaluate("aVarargsMethod2(8,new String[]{'a','b','c'})", 11, Integer.class);
}
@Test
public void testVarargsInvocation03() {
// Calling 'public int aVarargsMethod3(String str1, String... strings)' - returns all strings concatenated with "-"
// No conversion necessary
evaluate("aVarargsMethod3('x')", "x", String.class);
evaluate("aVarargsMethod3('x', 'a')", "x-a", String.class);
evaluate("aVarargsMethod3('x', 'a', 'b', 'c')", "x-a-b-c", String.class);
// Conversion necessary
evaluate("aVarargsMethod3(9)", "9", String.class);
evaluate("aVarargsMethod3(8,2,3)", "8-2-3", String.class);
evaluate("aVarargsMethod3('2','a',3.0d)", "2-a-3.0", String.class);
evaluate("aVarargsMethod3('8',new String[]{'a','b','c'})", "8-a-b-c", String.class);
// Individual string contains a comma with multiple varargs arguments
evaluate("aVarargsMethod3('foo', ',', 'baz')", "foo-,-baz", String.class);
evaluate("aVarargsMethod3('foo', 'bar', ',baz')", "foo-bar-,baz", String.class);
evaluate("aVarargsMethod3('foo', 'bar,', 'baz')", "foo-bar,-baz", String.class);
// Individual string contains a comma with single varargs argument.
// Reproduces https://github.com/spring-projects/spring-framework/issues/27582
evaluate("aVarargsMethod3('foo', ',')", "foo-,", String.class);
evaluate("aVarargsMethod3('foo', ',bar')", "foo-,bar", String.class);
evaluate("aVarargsMethod3('foo', 'bar,')", "foo-bar,", String.class);
evaluate("aVarargsMethod3('foo', 'bar,baz')", "foo-bar,baz", String.class);
// evaluate("aVarargsMethod2(8,new String[]{'a','b','c'})", 11, Integer.class);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -28,7 +28,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* Tests the evaluation of expressions that access variables and functions (lambda/java).
*
* @author Andy Clement
* @author Sam Brannen
*/
public class VariableAndFunctionTests extends AbstractExpressionTests {
@@ -59,17 +58,12 @@ public class VariableAndFunctionTests extends AbstractExpressionTests {
@Test
public void testCallVarargsFunction() {
evaluate("#varargsFunctionReverseStringsAndMerge('a,b')", "a,b", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge('a', 'b,c', 'd')", "db,ca", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge('a','b','c')", "cba", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge('a')", "a", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge()", "", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge('b',25)", "25b", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge(25)", "25", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge2(1, 'a,b')", "1a,b", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge2(1,'a','b','c')", "1cba", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge2(1, 'a', 'b,c', 'd')", "1db,ca", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge2(2,'a')", "2a", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge2(3)", "3", String.class);
evaluate("#varargsFunctionReverseStringsAndMerge2(4,'b',25)", "425b", String.class);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2016 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,7 +28,6 @@ import org.springframework.util.ObjectUtils;
///CLOVER:OFF
@SuppressWarnings("unused")
public class Inventor {
private String name;
public String _name;
public String _name_;
@@ -203,14 +202,8 @@ public class Inventor {
return strings.length + i;
}
public String aVarargsMethod3(String str1, String... strings) {
if (ObjectUtils.isEmpty(strings)) {
return str1;
}
return str1 + "-" + String.join("-", strings);
}
public Inventor(String... strings) {
}
public boolean getSomeProperty() {
@@ -230,10 +230,10 @@ public abstract class ExtendedEntityManagerCreator {
if (emIfc != null) {
interfaces = cachedEntityManagerInterfaces.computeIfAbsent(emIfc, key -> {
if (EntityManagerProxy.class.equals(key)) {
return new Class<?>[] {key};
}
return new Class<?>[] {key, EntityManagerProxy.class};
Set<Class<?>> ifcs = new LinkedHashSet<>(4);
ifcs.add(key);
ifcs.add(EntityManagerProxy.class);
return ClassUtils.toClassArray(ifcs);
});
}
else {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -373,7 +373,7 @@ public class PersistenceAnnotationBeanPostProcessor
}
private InjectionMetadata findPersistenceMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
@@ -393,7 +393,7 @@ public class PersistenceAnnotationBeanPostProcessor
return metadata;
}
private InjectionMetadata buildPersistenceMetadata(Class<?> clazz) {
private InjectionMetadata buildPersistenceMetadata(final Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, Arrays.asList(PersistenceContext.class, PersistenceUnit.class))) {
return InjectionMetadata.EMPTY;
}
@@ -17,7 +17,6 @@
package org.springframework.test.web.reactive.server;
import java.time.Duration;
import java.util.Objects;
import java.util.function.Consumer;
import org.hamcrest.Matcher;
@@ -211,10 +210,10 @@ public class CookieAssertions {
private ResponseCookie getCookie(String name) {
ResponseCookie cookie = this.exchangeResult.getResponseCookies().getFirst(name);
if (cookie == null) {
this.exchangeResult.assertWithDiagnostics(() ->
AssertionErrors.fail("No cookie with name '" + name + "'"));
String message = "No cookie with name '" + name + "'";
this.exchangeResult.assertWithDiagnostics(() -> AssertionErrors.fail(message));
}
return Objects.requireNonNull(cookie);
return cookie;
}
private String getMessage(String cookie) {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.test.web.reactive.server;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import org.hamcrest.Matcher;
@@ -74,7 +73,7 @@ public class HeaderAssertions {
String actual = getHeaders().getFirst(headerName);
this.exchangeResult.assertWithDiagnostics(() ->
assertTrue("Response does not contain header '" + headerName + "'", actual != null));
return assertHeader(headerName, value, Long.parseLong(Objects.requireNonNull(actual)));
return assertHeader(headerName, value, Long.parseLong(actual));
}
/**
@@ -116,7 +115,7 @@ public class HeaderAssertions {
/**
* Match all values of the response header with the given regex
* patterns which are applied to the values of the header in the
* same order. Note that the number of patterns must match the
* same order. Note that the number of pattenrs must match the
* number of actual values.
* @param name the header name
* @param patterns one or more regex patterns, one per expected value
@@ -204,7 +203,7 @@ public class HeaderAssertions {
this.exchangeResult.assertWithDiagnostics(() ->
AssertionErrors.fail(getMessage(name) + " not found"));
}
return Objects.requireNonNull(values);
return values;
}
/**
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2015 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.
@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
* PersistenceExceptionTranslator} interface, which are subsequently asked to translate
* candidate exceptions.
*
* <p>All of Spring's applicable resource factories (e.g.
* {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean})
* implement the {@code PersistenceExceptionTranslator} interface out of the box.
@@ -46,11 +47,6 @@ import org.springframework.util.Assert;
* with the {@code @Repository} annotation, along with defining this post-processor
* as a bean in the application context.
*
* <p>As of 5.3, {@code PersistenceExceptionTranslator} beans will be sorted according
* to Spring's dependency ordering rules: see {@link org.springframework.core.Ordered}
* and {@link org.springframework.core.annotation.Order}. Note that such beans will
* get retrieved from any scope, not just singleton scope, as of this 5.3 revision.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 2.0
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,12 +23,12 @@ import org.springframework.util.ObjectUtils;
/**
* Represents an HTTP request or response entity, consisting of headers and body.
*
* <p>Often used in combination with the {@link org.springframework.web.client.RestTemplate},
* <p>Typically used in combination with the {@link org.springframework.web.client.RestTemplate},
* like so:
* <pre class="code">
* HttpHeaders headers = new HttpHeaders();
* headers.setContentType(MediaType.TEXT_PLAIN);
* HttpEntity&lt;String&gt; entity = new HttpEntity&lt;&gt;("Hello World", headers);
* HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(helloWorld, headers);
* URI location = template.postForLocation("https://example.com", entity);
* </pre>
* or
@@ -39,11 +39,11 @@ import org.springframework.util.ObjectUtils;
* </pre>
* Can also be used in Spring MVC, as a return value from a @Controller method:
* <pre class="code">
* &#64;GetMapping("/handle")
* &#64;RequestMapping("/handle")
* public HttpEntity&lt;String&gt; handle() {
* HttpHeaders responseHeaders = new HttpHeaders();
* responseHeaders.set("MyResponseHeader", "MyValue");
* return new HttpEntity&lt;&gt;("Hello World", responseHeaders);
* return new HttpEntity&lt;String&gt;("Hello World", responseHeaders);
* }
* </pre>
*
@@ -63,7 +63,7 @@ public class DefaultPartHttpMessageReader extends LoggingCodecSupport implements
private int maxInMemorySize = 256 * 1024;
private int maxHeadersSize = 10 * 1024;
private int maxHeadersSize = 8 * 1024;
private long maxDiskUsagePerPart = -1;
@@ -16,15 +16,10 @@
package org.springframework.http.codec.multipart;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.concurrent.Callable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
@@ -55,40 +50,17 @@ abstract class DefaultParts {
}
/**
* Create a new {@link Part} or {@link FilePart} based on a flux of data
* buffers. Returns {@link FilePart} if the {@code Content-Disposition} of
* the given headers contains a filename, or a "normal" {@link Part}
* otherwise.
* @param headers the part headers
* @param dataBuffers the content of the part
* @return {@link Part} or {@link FilePart}, depending on {@link HttpHeaders#getContentDisposition()}
*/
public static Part part(HttpHeaders headers, Flux<DataBuffer> dataBuffers) {
Assert.notNull(headers, "Headers must not be null");
Assert.notNull(dataBuffers, "DataBuffers must not be null");
return partInternal(headers, new FluxContent(dataBuffers));
}
/**
* Create a new {@link Part} or {@link FilePart} based on the given file.
* Create a new {@link Part} or {@link FilePart} with the given parameters.
* Returns {@link FilePart} if the {@code Content-Disposition} of the given
* headers contains a filename, or a "normal" {@link Part} otherwise
* @param headers the part headers
* @param file the file
* @param scheduler the scheduler used for reading the file
* @param content the content of the part
* @return {@link Part} or {@link FilePart}, depending on {@link HttpHeaders#getContentDisposition()}
*/
public static Part part(HttpHeaders headers, Path file, Scheduler scheduler) {
public static Part part(HttpHeaders headers, Flux<DataBuffer> content) {
Assert.notNull(headers, "Headers must not be null");
Assert.notNull(file, "File must not be null");
Assert.notNull(scheduler, "Scheduler must not be null");
Assert.notNull(content, "Content must not be null");
return partInternal(headers, new FileContent(file, scheduler));
}
private static Part partInternal(HttpHeaders headers, Content content) {
String filename = headers.getContentDisposition().getFilename();
if (filename != null) {
return new DefaultFilePart(headers, content);
@@ -170,22 +142,16 @@ abstract class DefaultParts {
*/
private static class DefaultPart extends AbstractPart {
protected final Content content;
private final Flux<DataBuffer> content;
public DefaultPart(HttpHeaders headers, Content content) {
public DefaultPart(HttpHeaders headers, Flux<DataBuffer> content) {
super(headers);
this.content = content;
}
@Override
public Flux<DataBuffer> content() {
return this.content.content();
}
@Override
public Mono<Void> delete() {
return this.content.delete();
return this.content;
}
@Override
@@ -205,9 +171,9 @@ abstract class DefaultParts {
/**
* Default implementation of {@link FilePart}.
*/
private static final class DefaultFilePart extends DefaultPart implements FilePart {
private static class DefaultFilePart extends DefaultPart implements FilePart {
public DefaultFilePart(HttpHeaders headers, Content content) {
public DefaultFilePart(HttpHeaders headers, Flux<DataBuffer> content) {
super(headers, content);
}
@@ -220,7 +186,7 @@ abstract class DefaultParts {
@Override
public Mono<Void> transferTo(Path dest) {
return this.content.transferTo(dest);
return DataBufferUtils.write(content(), dest);
}
@Override
@@ -229,7 +195,7 @@ abstract class DefaultParts {
String name = contentDisposition.getName();
String filename = contentDisposition.getFilename();
if (name != null) {
return "DefaultFilePart{" + name + " (" + filename + ")}";
return "DefaultFilePart{" + name() + " (" + filename + ")}";
}
else {
return "DefaultFilePart{(" + filename + ")}";
@@ -238,100 +204,4 @@ abstract class DefaultParts {
}
/**
* Part content abstraction.
*/
private interface Content {
Flux<DataBuffer> content();
Mono<Void> transferTo(Path dest);
Mono<Void> delete();
}
/**
* {@code Content} implementation based on a flux of data buffers.
*/
private static final class FluxContent implements Content {
private final Flux<DataBuffer> content;
public FluxContent(Flux<DataBuffer> content) {
this.content = content;
}
@Override
public Flux<DataBuffer> content() {
return this.content;
}
@Override
public Mono<Void> transferTo(Path dest) {
return DataBufferUtils.write(this.content, dest);
}
@Override
public Mono<Void> delete() {
return Mono.empty();
}
}
/**
* {@code Content} implementation based on a file.
*/
private static final class FileContent implements Content {
private final Path file;
private final Scheduler scheduler;
public FileContent(Path file, Scheduler scheduler) {
this.file = file;
this.scheduler = scheduler;
}
@Override
public Flux<DataBuffer> content() {
return DataBufferUtils.readByteChannel(
() -> Files.newByteChannel(this.file, StandardOpenOption.READ),
DefaultDataBufferFactory.sharedInstance, 1024)
.subscribeOn(this.scheduler);
}
@Override
public Mono<Void> transferTo(Path dest) {
return blockingOperation(() -> Files.copy(this.file, dest, StandardCopyOption.REPLACE_EXISTING));
}
@Override
public Mono<Void> delete() {
return blockingOperation(() -> {
Files.delete(this.file);
return null;
});
}
private Mono<Void> blockingOperation(Callable<?> callable) {
return Mono.<Void>create(sink -> {
try {
callable.call();
sink.success();
}
catch (Exception ex) {
sink.error(ex);
}
})
.subscribeOn(this.scheduler);
}
}
}
@@ -342,23 +342,33 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
/**
* First checks whether the multipart boundary leading to this state
* was the final boundary. Then looks for the header-body boundary
* ({@code CR LF CR LF}) in the given buffer. If found, checks whether
* the size of all header buffers does not exceed {@link #maxHeadersSize},
* converts all buffers collected so far into a {@link HttpHeaders} object
* was the final boundary, or whether {@link #maxHeadersSize} is
* exceeded. Then looks for the header-body boundary
* ({@code CR LF CR LF}) in the given buffer. If found, convert
* all buffers collected so far into a {@link HttpHeaders} object
* and changes to {@link BodyState}, passing the remainder of the
* buffer. If the boundary is not found, the buffer is collected if
* its size does not exceed {@link #maxHeadersSize}.
* buffer. If the boundary is not found, the buffer is collected.
*/
@Override
public void onNext(DataBuffer buf) {
if (isLastBoundary(buf)) {
if (logger.isTraceEnabled()) {
logger.trace("Last boundary found in " + buf);
}
long prevCount = this.byteCount.get();
long count = this.byteCount.addAndGet(buf.readableByteCount());
if (prevCount < 2 && count >= 2) {
if (isLastBoundary(buf)) {
if (logger.isTraceEnabled()) {
logger.trace("Last boundary found in " + buf);
}
if (changeState(this, DisposedState.INSTANCE, buf)) {
emitComplete();
}
return;
}
}
else if (count > MultipartParser.this.maxHeadersSize) {
if (changeState(this, DisposedState.INSTANCE, buf)) {
emitComplete();
emitError(new DataBufferLimitException("Part headers exceeded the memory usage limit of " +
MultipartParser.this.maxHeadersSize + " bytes"));
}
return;
}
@@ -367,23 +377,17 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
if (logger.isTraceEnabled()) {
logger.trace("End of headers found @" + endIdx + " in " + buf);
}
long count = this.byteCount.addAndGet(endIdx);
if (belowMaxHeaderSize(count)) {
DataBuffer headerBuf = MultipartUtils.sliceTo(buf, endIdx);
this.buffers.add(headerBuf);
DataBuffer bodyBuf = MultipartUtils.sliceFrom(buf, endIdx);
DataBufferUtils.release(buf);
DataBuffer headerBuf = MultipartUtils.sliceTo(buf, endIdx);
this.buffers.add(headerBuf);
DataBuffer bodyBuf = MultipartUtils.sliceFrom(buf, endIdx);
DataBufferUtils.release(buf);
emitHeaders(parseHeaders());
changeState(this, new BodyState(), bodyBuf);
}
emitHeaders(parseHeaders());
changeState(this, new BodyState(), bodyBuf);
}
else {
long count = this.byteCount.addAndGet(buf.readableByteCount());
if (belowMaxHeaderSize(count)) {
this.buffers.add(buf);
requestBuffer();
}
this.buffers.add(buf);
requestBuffer();
}
}
@@ -403,21 +407,6 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
buf.getByte(0) == HYPHEN);
}
/**
* Checks whether the given {@code count} is below or equal to {@link #maxHeadersSize}
* and emits a {@link DataBufferLimitException} if not.
*/
private boolean belowMaxHeaderSize(long count) {
if (count <= MultipartParser.this.maxHeadersSize) {
return true;
}
else {
emitError(new DataBufferLimitException("Part headers exceeded the memory usage limit of " +
MultipartParser.this.maxHeadersSize + " bytes"));
return false;
}
}
/**
* Parses the list of buffers into a {@link HttpHeaders} instance.
* Converts the joined buffers into a string using ISO=8859-1, and parses
@@ -17,7 +17,6 @@
package org.springframework.http.codec.multipart;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
@@ -58,13 +57,4 @@ public interface Part {
*/
Flux<DataBuffer> content();
/**
* Return a mono that, when subscribed to, deletes the underlying storage
* for this part.
* @since 5.3.13
*/
default Mono<Void> delete() {
return Mono.empty();
}
}
@@ -674,12 +674,21 @@ final class PartGenerator extends BaseSubscriber<MultipartParser.Token> {
@Override
public void partComplete(boolean finalPart) {
MultipartUtils.closeChannel(this.channel);
emitPart(DefaultParts.part(this.headers, this.file, PartGenerator.this.blockingOperationScheduler));
Flux<DataBuffer> content = partContent();
emitPart(DefaultParts.part(this.headers, content));
if (finalPart) {
emitComplete();
}
}
private Flux<DataBuffer> partContent() {
return DataBufferUtils
.readByteChannel(
() -> Files.newByteChannel(this.file, StandardOpenOption.READ),
DefaultDataBufferFactory.sharedInstance, 1024)
.subscribeOn(PartGenerator.this.blockingOperationScheduler);
}
@Override
public void dispose() {
if (this.closeOnDispose) {
@@ -16,9 +16,7 @@
package org.springframework.http.codec.multipart;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
@@ -42,7 +40,6 @@ import org.synchronoss.cloud.nio.multipart.MultipartUtils;
import org.synchronoss.cloud.nio.multipart.NioMultipartParser;
import org.synchronoss.cloud.nio.multipart.NioMultipartParserListener;
import org.synchronoss.cloud.nio.multipart.PartBodyStreamStorageFactory;
import org.synchronoss.cloud.nio.stream.storage.NameAwarePurgableFileInputStream;
import org.synchronoss.cloud.nio.stream.storage.StreamStorage;
import reactor.core.publisher.BaseSubscriber;
import reactor.core.publisher.Flux;
@@ -500,38 +497,6 @@ public class SynchronossPartHttpMessageReader extends LoggingCodecSupport implem
protected StreamStorage getStorage() {
return this.storage;
}
@Override
public Mono<Void> delete() {
return Mono.fromRunnable(() -> {
File file = getFile();
if (file != null) {
file.delete();
}
});
}
@Nullable
private File getFile() {
InputStream inputStream = null;
try {
inputStream = getStorage().getInputStream();
if (inputStream instanceof NameAwarePurgableFileInputStream) {
NameAwarePurgableFileInputStream stream = (NameAwarePurgableFileInputStream) inputStream;
return stream.getFile();
}
}
finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException ignore) {
}
}
}
return null;
}
}
@@ -17,7 +17,6 @@
package org.springframework.http.server.reactive;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -37,7 +36,6 @@ import org.springframework.util.MultiValueMap;
* {@code MultiValueMap} implementation for wrapping Undertow HTTP headers.
*
* @author Brian Clozel
* @author Sam Brannen
* @since 5.1.1
*/
class UndertowHeadersAdapter implements MultiValueMap<String, String> {
@@ -133,10 +131,7 @@ class UndertowHeadersAdapter implements MultiValueMap<String, String> {
@Nullable
public List<String> remove(Object key) {
if (key instanceof String) {
Collection<String> removed = this.headers.remove((String) key);
if (removed != null) {
return new ArrayList<>(removed);
}
this.headers.remove((String) key);
}
return null;
}
@@ -405,18 +405,16 @@ public class UrlPathHelper {
* </ul>
*/
private static String getSanitizedPath(final String path) {
int start = path.indexOf("//");
if (start == -1) {
return path;
}
char[] content = path.toCharArray();
int slowIndex = start;
for (int fastIndex = start + 1; fastIndex < content.length; fastIndex++) {
if (content[fastIndex] != '/' || content[slowIndex] != '/') {
content[++slowIndex] = content[fastIndex];
int index = path.indexOf("//");
if (index >= 0) {
StringBuilder sanitized = new StringBuilder(path);
while (index != -1) {
sanitized.deleteCharAt(index);
index = sanitized.indexOf("//", index);
}
return sanitized.toString();
}
return new String(content, 0, slowIndex + 1);
return path;
}
/**
@@ -534,7 +532,7 @@ public class UrlPathHelper {
*/
public String getOriginatingQueryString(HttpServletRequest request) {
if ((request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) != null) ||
(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE) != null)) {
return (String) request.getAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE);
}
else {
@@ -270,31 +270,6 @@ public class DefaultPartHttpMessageReaderTests {
latch.await();
}
// gh-27612
@Test
public void exceedHeaderLimit() throws InterruptedException {
Flux<DataBuffer> body = DataBufferUtils
.readByteChannel((new ClassPathResource("files.multipart", getClass()))::readableChannel, bufferFactory, 282);
MediaType contentType = new MediaType("multipart", "form-data", singletonMap("boundary", "----WebKitFormBoundaryG8fJ50opQOML0oGD"));
MockServerHttpRequest request = MockServerHttpRequest.post("/")
.contentType(contentType)
.body(body);
DefaultPartHttpMessageReader reader = new DefaultPartHttpMessageReader();
reader.setMaxHeadersSize(230);
Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
CountDownLatch latch = new CountDownLatch(2);
StepVerifier.create(result)
.consumeNextWith(part -> testPart(part, null, LOREM_IPSUM, latch))
.consumeNextWith(part -> testPart(part, null, MUSPI_MEROL, latch))
.verifyComplete();
latch.await();
}
private void testBrowser(DefaultPartHttpMessageReader reader, Resource resource, String boundary)
throws InterruptedException {
@@ -232,12 +232,12 @@ class UrlPathHelperTests {
request.setContextPath("/SPR-12372");
request.setPathInfo(null);
request.setServletPath("/foo/bar/");
request.setRequestURI("/SPR-12372/foo///bar/");
request.setRequestURI("/SPR-12372/foo//bar/");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar/");
request.setServletPath("/foo/bar/");
request.setRequestURI("////SPR-12372/foo/bar//");
request.setRequestURI("/SPR-12372/foo/bar//");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar/");
@@ -246,12 +246,6 @@ class UrlPathHelperTests {
request.setRequestURI("/SPR-12372/foo/bar//");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar//");
// "enhance" case
request.setServletPath("/foo/bar//");
request.setRequestURI("/SPR-12372////////////////////////foo//////////////////bar////////////////////");
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar//");
}
@Test
@@ -3,9 +3,11 @@ Content-Disposition: form-data; name="file2"; filename="a.txt"
Content-Type: text/plain
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer iaculis metus id vestibulum nullam.
------WebKitFormBoundaryG8fJ50opQOML0oGD
Content-Disposition: form-data; name="file2"; filename="b.txt"
Content-Type: text/plain
.mallun mulubitsev di sutem silucai regetnI .tile gnicsipida rutetcesnoc ,tema tis rolod muspi meroL
------WebKitFormBoundaryG8fJ50opQOML0oGD--
@@ -54,8 +54,6 @@ public class ResourceHandlerRegistration {
private boolean useLastModified = true;
private boolean optimizeLocations = false;
@Nullable
private Map<String, MediaType> mediaTypes;
@@ -107,33 +105,15 @@ public class ResourceHandlerRegistration {
/**
* Set whether the {@link Resource#lastModified()} information should be used to drive HTTP responses.
* <p>This configuration is set to {@code true} by default.
* @param useLastModified whether the "last modified" resource information should be used
* @param useLastModified whether the "last modified" resource information should be used.
* @return the same {@link ResourceHandlerRegistration} instance, for chained method invocation
* @since 5.3
* @see ResourceWebHandler#setUseLastModified
*/
public ResourceHandlerRegistration setUseLastModified(boolean useLastModified) {
this.useLastModified = useLastModified;
return this;
}
/**
* Set whether to optimize the specified locations through an existence check on startup,
* filtering non-existing directories upfront so that they do not have to be checked
* on every resource access.
* <p>The default is {@code false}, for defensiveness against zip files without directory
* entries which are unable to expose the existence of a directory upfront. Switch this flag to
* {@code true} for optimized access in case of a consistent jar layout with directory entries.
* @param optimizeLocations whether to optimize the locations through an existence check on startup
* @return the same {@link ResourceHandlerRegistration} instance, for chained method invocation
* @since 5.3.13
* @see ResourceWebHandler#setOptimizeLocations
*/
public ResourceHandlerRegistration setOptimizeLocations(boolean optimizeLocations) {
this.optimizeLocations = optimizeLocations;
return this;
}
/**
* Configure a chain of resource resolvers and transformers to use. This
* can be useful, for example, to apply a version strategy to resource URLs.
@@ -201,8 +181,8 @@ public class ResourceHandlerRegistration {
*/
protected ResourceWebHandler getRequestHandler() {
ResourceWebHandler handler = new ResourceWebHandler();
handler.setResourceLoader(this.resourceLoader);
handler.setLocationValues(this.locationValues);
handler.setResourceLoader(this.resourceLoader);
if (this.resourceChainRegistration != null) {
handler.setResourceResolvers(this.resourceChainRegistration.getResourceResolvers());
handler.setResourceTransformers(this.resourceChainRegistration.getResourceTransformers());
@@ -211,7 +191,6 @@ public class ResourceHandlerRegistration {
handler.setCacheControl(this.cacheControl);
}
handler.setUseLastModified(this.useLastModified);
handler.setOptimizeLocations(this.optimizeLocations);
if (this.mediaTypes != null) {
handler.setMediaTypes(this.mediaTypes);
}
@@ -195,7 +195,13 @@ class DefaultClientResponse implements ClientResponse {
@Override
public Mono<WebClientResponseException> createException() {
return bodyToMono(byte[].class)
return DataBufferUtils.join(body(BodyExtractors.toDataBuffers()))
.map(dataBuffer -> {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);
return bytes;
})
.defaultIfEmpty(EMPTY)
.onErrorReturn(ex -> !(ex instanceof Error), EMPTY)
.map(bodyBytes -> {
@@ -72,8 +72,8 @@ import org.springframework.web.server.WebHandler;
* <p>This request handler may also be configured with a
* {@link #setResourceResolvers(List) resourcesResolver} and
* {@link #setResourceTransformers(List) resourceTransformer} chains to support
* arbitrary resolution and transformation of resources being served. By default
* a {@link PathResourceResolver} simply finds resources based on the configured
* arbitrary resolution and transformation of resources being served. By default a
* {@link PathResourceResolver} simply finds resources based on the configured
* "locations". An application can configure additional resolvers and
* transformers such as the {@link VersionResourceResolver} which can resolve
* and prepare URLs for resources with a version in the URL.
@@ -85,7 +85,6 @@ import org.springframework.web.server.WebHandler;
*
* @author Rossen Stoyanchev
* @author Brian Clozel
* @author Juergen Hoeller
* @since 5.0
*/
public class ResourceWebHandler implements WebHandler, InitializingBean {
@@ -95,9 +94,6 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
private static final Log logger = LogFactory.getLog(ResourceWebHandler.class);
@Nullable
private ResourceLoader resourceLoader;
private final List<String> locationValues = new ArrayList<>(4);
private final List<Resource> locationResources = new ArrayList<>(4);
@@ -123,18 +119,11 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
@Nullable
private Map<String, MediaType> mediaTypes;
@Nullable
private ResourceLoader resourceLoader;
private boolean useLastModified = true;
private boolean optimizeLocations = false;
/**
* Provide the ResourceLoader to load {@link #setLocationValues location values} with.
* @since 5.1
*/
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
/**
* Accepts a list of String-based location values to be resolved into
@@ -172,9 +161,9 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
* <p>Note that if {@link #setLocationValues(List) locationValues} are provided,
* instead of loaded Resource-based locations, this method will return
* empty until after initialization via {@link #afterPropertiesSet()}.
* <p><strong>Note:</strong> As of 5.3.11 the list of locations may be filtered to
* exclude those that don't actually exist and therefore the list returned from this
* method may be a subset of all given locations. See {@link #setOptimizeLocations}.
* <p><strong>Note:</strong> As of 5.3.11 the list of locations is filtered
* to exclude those that don't actually exist and therefore the list returned
* from this method may be a subset of all given locations.
* @see #setLocationValues
* @see #setLocations
*/
@@ -223,22 +212,6 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
return this.resourceTransformers;
}
/**
* Configure the {@link ResourceHttpMessageWriter} to use.
* <p>By default a {@link ResourceHttpMessageWriter} will be configured.
*/
public void setResourceHttpMessageWriter(@Nullable ResourceHttpMessageWriter httpMessageWriter) {
this.resourceHttpMessageWriter = httpMessageWriter;
}
/**
* Return the configured resource message writer.
*/
@Nullable
public ResourceHttpMessageWriter getResourceHttpMessageWriter() {
return this.resourceHttpMessageWriter;
}
/**
* Set the {@link org.springframework.http.CacheControl} instance to build
* the Cache-Control HTTP response header.
@@ -257,48 +230,19 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
}
/**
* Set whether we should look at the {@link Resource#lastModified()}
* when serving resources and use this information to drive {@code "Last-Modified"}
* HTTP response headers.
* <p>This option is enabled by default and should be turned off if the metadata of
* the static files should be ignored.
* @since 5.3
* Configure the {@link ResourceHttpMessageWriter} to use.
* <p>By default a {@link ResourceHttpMessageWriter} will be configured.
*/
public void setUseLastModified(boolean useLastModified) {
this.useLastModified = useLastModified;
public void setResourceHttpMessageWriter(@Nullable ResourceHttpMessageWriter httpMessageWriter) {
this.resourceHttpMessageWriter = httpMessageWriter;
}
/**
* Return whether the {@link Resource#lastModified()} information is used
* to drive HTTP responses when serving static resources.
* @since 5.3
* Return the configured resource message writer.
*/
public boolean isUseLastModified() {
return this.useLastModified;
}
/**
* Set whether to optimize the specified locations through an existence
* check on startup, filtering non-existing directories upfront so that
* they do not have to be checked on every resource access.
* <p>The default is {@code false}, for defensiveness against zip files
* without directory entries which are unable to expose the existence of
* a directory upfront. Switch this flag to {@code true} for optimized
* access in case of a consistent jar layout with directory entries.
* @since 5.3.13
*/
public void setOptimizeLocations(boolean optimizeLocations) {
this.optimizeLocations = optimizeLocations;
}
/**
* Return whether to optimize the specified locations through an existence
* check on startup, filtering non-existing directories upfront so that
* they do not have to be checked on every resource access.
* @since 5.3.13
*/
public boolean isOptimizeLocations() {
return this.optimizeLocations;
@Nullable
public ResourceHttpMessageWriter getResourceHttpMessageWriter() {
return this.resourceHttpMessageWriter;
}
/**
@@ -325,6 +269,36 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
return (this.mediaTypes != null ? this.mediaTypes : Collections.emptyMap());
}
/**
* Provide the ResourceLoader to load {@link #setLocationValues(List)
* location values} with.
* @since 5.1
*/
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
/**
* Return whether the {@link Resource#lastModified()} information is used
* to drive HTTP responses when serving static resources.
* @since 5.3
*/
public boolean isUseLastModified() {
return this.useLastModified;
}
/**
* Set whether we should look at the {@link Resource#lastModified()}
* when serving resources and use this information to drive {@code "Last-Modified"}
* HTTP response headers.
* <p>This option is enabled by default and should be turned off if the metadata of
* the static files should be ignored.
* @param useLastModified whether to use the resource last-modified information.
* @since 5.3
*/
public void setUseLastModified(boolean useLastModified) {
this.useLastModified = useLastModified;
}
@Override
public void afterPropertiesSet() throws Exception {
@@ -358,9 +332,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
}
}
if (isOptimizeLocations()) {
result = result.stream().filter(Resource::exists).collect(Collectors.toList());
}
result = result.stream().filter(Resource::exists).collect(Collectors.toList());
this.locationsToUse.clear();
this.locationsToUse.addAll(result);
@@ -30,7 +30,6 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.codec.ByteArrayDecoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DefaultDataBuffer;
@@ -49,7 +48,6 @@ import org.springframework.util.MultiValueMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
@@ -330,29 +328,6 @@ public class DefaultClientResponseTests {
assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
}
@Test
public void createException() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
given(mockResponse.getStatusCode()).willReturn(HttpStatus.NOT_FOUND);
given(mockResponse.getRawStatusCode()).willReturn(HttpStatus.NOT_FOUND.value());
given(mockResponse.getBody()).willReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(
new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<WebClientResponseException> resultMono = defaultClientResponse.createException();
WebClientResponseException exception = resultMono.block();
assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getMessage()).isEqualTo("404 Not Found");
assertThat(exception.getHeaders()).containsExactly(entry("Content-Type",
Collections.singletonList("text/plain")));
assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes);
}
private void mockTextPlainResponse(Flux<DataBuffer> body) {
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -133,7 +133,6 @@ public class DefaultWebClientTests {
}
@Test
@SuppressWarnings("deprecation")
public void contextFromThreadLocal() {
WebClient client = this.builder
.filter((request, next) ->
@@ -74,7 +74,6 @@ public class ResourceWebHandlerTests {
private ResourceWebHandler handler;
@BeforeEach
public void setup() throws Exception {
List<Resource> locations = new ArrayList<>(2);
@@ -254,7 +253,7 @@ public class ResourceWebHandlerTests {
assertResponseBody(exchange, "h1 { color:red; }");
}
@Test // gh-27538, gh-27624
@Test // gh-27538
public void filterNonExistingLocations() throws Exception {
List<Resource> inputLocations = Arrays.asList(
new ClassPathResource("test/", getClass()),
@@ -263,7 +262,6 @@ public class ResourceWebHandlerTests {
ResourceWebHandler handler = new ResourceWebHandler();
handler.setLocations(inputLocations);
handler.setOptimizeLocations(true);
handler.afterPropertiesSet();
List<Resource> actual = handler.getLocations();
@@ -55,8 +55,6 @@ public class ResourceHandlerRegistration {
private boolean useLastModified = true;
private boolean optimizeLocations = false;
/**
* Create a {@link ResourceHandlerRegistration} instance.
@@ -132,33 +130,15 @@ public class ResourceHandlerRegistration {
/**
* Set whether the {@link Resource#lastModified()} information should be used to drive HTTP responses.
* <p>This configuration is set to {@code true} by default.
* @param useLastModified whether the "last modified" resource information should be used
* @param useLastModified whether the "last modified" resource information should be used.
* @return the same {@link ResourceHandlerRegistration} instance, for chained method invocation
* @since 5.3
* @see ResourceHttpRequestHandler#setUseLastModified
*/
public ResourceHandlerRegistration setUseLastModified(boolean useLastModified) {
this.useLastModified = useLastModified;
return this;
}
/**
* Set whether to optimize the specified locations through an existence check on startup,
* filtering non-existing directories upfront so that they do not have to be checked
* on every resource access.
* <p>The default is {@code false}, for defensiveness against zip files without directory
* entries which are unable to expose the existence of a directory upfront. Switch this flag to
* {@code true} for optimized access in case of a consistent jar layout with directory entries.
* @param optimizeLocations whether to optimize the locations through an existence check on startup
* @return the same {@link ResourceHandlerRegistration} instance, for chained method invocation
* @since 5.3.13
* @see ResourceHttpRequestHandler#setOptimizeLocations
*/
public ResourceHandlerRegistration setOptimizeLocations(boolean optimizeLocations) {
this.optimizeLocations = optimizeLocations;
return this;
}
/**
* Configure a chain of resource resolvers and transformers to use. This
* can be useful, for example, to apply a version strategy to resource URLs.
@@ -224,7 +204,6 @@ public class ResourceHandlerRegistration {
handler.setCacheSeconds(this.cachePeriod);
}
handler.setUseLastModified(this.useLastModified);
handler.setOptimizeLocations(this.optimizeLocations);
return handler;
}
@@ -140,13 +140,11 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
@Nullable
private UrlPathHelper urlPathHelper;
private boolean useLastModified = true;
private boolean optimizeLocations = false;
@Nullable
private StringValueResolver embeddedValueResolver;
private boolean useLastModified = true;
public ResourceHttpRequestHandler() {
super(HttpMethod.GET.name(), HttpMethod.HEAD.name());
@@ -187,13 +185,13 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
/**
* Return the configured {@code List} of {@code Resource} locations including
* both String-based locations provided via
* {@link #setLocationValues(List) setLocationValues} and pre-resolved
* {@code Resource} locations provided via {@link #setLocations(List) setLocations}.
* {@link #setLocationValues(List) setLocationValues} and pre-resolved {@code Resource}
* locations provided via {@link #setLocations(List) setLocations}.
* <p>Note that the returned list is fully initialized only after
* initialization via {@link #afterPropertiesSet()}.
* <p><strong>Note:</strong> As of 5.3.11 the list of locations may be filtered to
* exclude those that don't actually exist and therefore the list returned from this
* method may be a subset of all given locations. See {@link #setOptimizeLocations}.
* <p><strong>Note:</strong> As of 5.3.11 the list of locations is filtered
* to exclude those that don't actually exist and therefore the list returned
* from this method may be a subset of all given locations.
* @see #setLocationValues
* @see #setLocations
*/
@@ -295,7 +293,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
/**
* Return the configured content negotiation manager.
* @since 4.3
* @deprecated as of 5.2.4
* @deprecated as of 5.2.4.
*/
@Nullable
@Deprecated
@@ -305,7 +303,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
/**
* Add mappings between file extensions, extracted from the filename of a
* static {@link Resource}, and corresponding media type to set on the
* static {@link Resource}, and corresponding media type to set on the
* response.
* <p>Use of this method is typically not necessary since mappings are
* otherwise determined via
@@ -363,16 +361,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
return this.urlPathHelper;
}
/**
* Set whether we should look at the {@link Resource#lastModified()} when
* serving resources and use this information to drive {@code "Last-Modified"}
* HTTP response headers.
* <p>This option is enabled by default and should be turned off if the metadata
* of the static files should be ignored.
* @since 5.3
*/
public void setUseLastModified(boolean useLastModified) {
this.useLastModified = useLastModified;
@Override
public void setEmbeddedValueResolver(StringValueResolver resolver) {
this.embeddedValueResolver = resolver;
}
/**
@@ -385,35 +376,18 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
}
/**
* Set whether to optimize the specified locations through an existence
* check on startup, filtering non-existing directories upfront so that
* they do not have to be checked on every resource access.
* <p>The default is {@code false}, for defensiveness against zip files
* without directory entries which are unable to expose the existence of
* a directory upfront. Switch this flag to {@code true} for optimized
* access in case of a consistent jar layout with directory entries.
* @since 5.3.13
* Set whether we should look at the {@link Resource#lastModified()}
* when serving resources and use this information to drive {@code "Last-Modified"}
* HTTP response headers.
* <p>This option is enabled by default and should be turned off if the metadata of
* the static files should be ignored.
* @param useLastModified whether to use the resource last-modified information.
* @since 5.3
*/
public void setOptimizeLocations(boolean optimizeLocations) {
this.optimizeLocations = optimizeLocations;
public void setUseLastModified(boolean useLastModified) {
this.useLastModified = useLastModified;
}
/**
* Return whether to optimize the specified locations through an existence
* check on startup, filtering non-existing directories upfront so that
* they do not have to be checked on every resource access.
* @since 5.3.13
*/
public boolean isOptimizeLocations() {
return this.optimizeLocations;
}
@Override
public void setEmbeddedValueResolver(StringValueResolver resolver) {
this.embeddedValueResolver = resolver;
}
@Override
public void afterPropertiesSet() throws Exception {
resolveResourceLocations();
@@ -475,8 +449,8 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
if (location.equals("/") && !(resource instanceof ServletContextResource)) {
throw new IllegalStateException(
"The String-based location \"/\" should be relative to the web application root " +
"but resolved to a Resource of type: " + resource.getClass() + ". " +
"If this is intentional, please pass it as a pre-configured Resource via setLocations.");
"but resolved to a Resource of type: " + resource.getClass() + ". " +
"If this is intentional, please pass it as a pre-configured Resource via setLocations.");
}
result.add(resource);
if (charset != null) {
@@ -489,9 +463,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
}
result.addAll(this.locationResources);
if (isOptimizeLocations()) {
result = result.stream().filter(Resource::exists).collect(Collectors.toList());
}
result = result.stream().filter(Resource::exists).collect(Collectors.toList());
this.locationsToUse.clear();
this.locationsToUse.addAll(result);
@@ -536,7 +508,6 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
return null;
}
/**
* Processes a resource request.
* <p>Checks for the existence of the requested resource in the configured list of locations.
@@ -311,7 +311,7 @@ public class ResourceHttpRequestHandlerTests {
assertThat(this.response.getContentAsString()).isEqualTo("h1 { color:red; }");
}
@Test // gh-27538, gh-27624
@Test // gh-27538
public void filterNonExistingLocations() throws Exception {
List<Resource> inputLocations = Arrays.asList(
new ClassPathResource("test/", getClass()),
@@ -321,7 +321,6 @@ public class ResourceHttpRequestHandlerTests {
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setServletContext(new MockServletContext());
handler.setLocations(inputLocations);
handler.setOptimizeLocations(true);
handler.afterPropertiesSet();
List<Resource> actual = handler.getLocations();
+4 -6
View File
@@ -3039,7 +3039,7 @@ constructor or setter argument or autowired field) as `ObjectFactory<MyTargetBea
allowing for a `getObject()` call to retrieve the current instance on demand every
time it is needed -- without holding on to the instance or storing it separately.
As an extended variant, you may declare `ObjectProvider<MyTargetBean>` which delivers
As an extended variant, you may declare `ObjectProvider<MyTargetBean>`, which delivers
several additional access variants, including `getIfAvailable` and `getIfUnique`.
The JSR-330 variant of this is called `Provider` and is used with a `Provider<MyTargetBean>`
@@ -6675,11 +6675,9 @@ factory method and other bean definition properties, such as a qualifier value t
the `@Qualifier` annotation. Other method-level annotations that can be specified are
`@Scope`, `@Lazy`, and custom qualifier annotations.
TIP: In addition to its role for component initialization, you can also place the `@Lazy`
annotation on injection points marked with `@Autowired` or `@Inject`. In this context,
it leads to the injection of a lazy-resolution proxy. However, such a proxy approach
is rather limited. For sophisticated lazy interactions, in particular in combination
with optional dependencies, we recommend `ObjectProvider<MyTargetBean>` instead.
TIP: In addition to its role for component initialization, you can also place the `@Lazy` annotation
on injection points marked with `@Autowired` or `@Inject`. In this context, it
leads to the injection of a lazy-resolution proxy.
Autowired fields and methods are supported, as previously discussed, with additional
support for autowiring of `@Bean` methods. The following example shows how to do so:
+1 -1
View File
@@ -89,7 +89,7 @@ modified copy as follows:
=== MaxInMemorySize
Codecs have <<web-reactive.adoc#webflux-codecs-limits,limits>> for buffering data in
memory to avoid application memory issues. By default those are set to 256KB.
memory to avoid application memory issues. By the default those are set to 256KB.
If that's not enough you'll get the following error:
----
+2 -5
View File
@@ -4170,8 +4170,8 @@ the example:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/public", "classpath:/static/")
.setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS));
.addResourceLocations("/public", "classpath:/static/")
.setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS));
}
}
@@ -4259,9 +4259,6 @@ re-write URLs to include the version of the jar and can also match against incom
without versions -- for example, from `/jquery/jquery.min.js` to
`/jquery/1.2.0/jquery.min.js`.
TIP: The Java configuration based on `ResourceHandlerRegistry` provides further options
for fine-grained control, e.g. last-modified behavior and optimized resource resolution.
[[webflux-config-path-matching]]
+2 -5
View File
@@ -5738,8 +5738,8 @@ The following listing shows how to do so with Java configuration:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/public", "classpath:/static/")
.setCacheControl(CacheControl.maxAge(Duration.ofDays(365)));
.addResourceLocations("/public", "classpath:/static/")
.setCacheControl(CacheControl.maxAge(Duration.ofDays(365)));
}
}
----
@@ -5846,9 +5846,6 @@ re-write URLs to include the version of the jar and can also match against incom
without versions -- for example, from `/jquery/jquery.min.js` to
`/jquery/1.2.0/jquery.min.js`.
TIP: The Java configuration based on `ResourceHandlerRegistry` provides further options
for fine-grained control, e.g. last-modified behavior and optimized resource resolution.
[[mvc-default-servlet-handler]]