Browse Source

Merge branch '5.2.x'

pull/25428/head
Juergen Hoeller 6 years ago
parent
commit
e4e54b3c4a
  1. 30
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  2. 22
      spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
  3. 14
      spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java
  4. 40
      spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java
  5. 9
      spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java

30
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -593,6 +593,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -593,6 +593,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
// Register exception, in case the bean was accidentally unresolvable.
onSuppressedException(ex);
}
catch (NoSuchBeanDefinitionException ex) {
// Bean definition got removed while we were iterating -> ignore.
}
}
}
@ -684,7 +687,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -684,7 +687,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType) {
List<String> result = new ArrayList<>();
for (String beanName : this.beanDefinitionNames) {
BeanDefinition beanDefinition = getBeanDefinition(beanName);
BeanDefinition beanDefinition = this.beanDefinitionMap.get(beanName);
if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) {
result.add(beanName);
}
@ -1754,18 +1757,23 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -1754,18 +1757,23 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
*/
private void checkBeanNotOfRequiredType(Class<?> type, DependencyDescriptor descriptor) {
for (String beanName : this.beanDefinitionNames) {
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
Class<?> targetType = mbd.getTargetType();
if (targetType != null && type.isAssignableFrom(targetType) &&
isAutowireCandidate(beanName, mbd, descriptor, getAutowireCandidateResolver())) {
// Probably a proxy interfering with target type match -> throw meaningful exception.
Object beanInstance = getSingleton(beanName, false);
Class<?> beanType = (beanInstance != null && beanInstance.getClass() != NullBean.class ?
beanInstance.getClass() : predictBeanType(beanName, mbd));
if (beanType != null && !type.isAssignableFrom(beanType)) {
throw new BeanNotOfRequiredTypeException(beanName, type, beanType);
try {
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
Class<?> targetType = mbd.getTargetType();
if (targetType != null && type.isAssignableFrom(targetType) &&
isAutowireCandidate(beanName, mbd, descriptor, getAutowireCandidateResolver())) {
// Probably a proxy interfering with target type match -> throw meaningful exception.
Object beanInstance = getSingleton(beanName, false);
Class<?> beanType = (beanInstance != null && beanInstance.getClass() != NullBean.class ?
beanInstance.getClass() : predictBeanType(beanName, mbd));
if (beanType != null && !type.isAssignableFrom(beanType)) {
throw new BeanNotOfRequiredTypeException(beanName, type, beanType);
}
}
}
catch (NoSuchBeanDefinitionException ex) {
// Bean definition got removed while we were iterating -> ignore.
}
}
BeanFactory parent = getParentBeanFactory();

22
spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -256,7 +256,10 @@ public class ScheduledAnnotationBeanPostProcessor @@ -256,7 +256,10 @@ public class ScheduledAnnotationBeanPostProcessor
this.registrar.setTaskScheduler(resolveSchedulerBean(this.beanFactory, TaskScheduler.class, false));
}
catch (NoUniqueBeanDefinitionException ex) {
logger.trace("Could not find unique TaskScheduler bean", ex);
if (logger.isTraceEnabled()) {
logger.trace("Could not find unique TaskScheduler bean - attempting to resolve by name: " +
ex.getMessage());
}
try {
this.registrar.setTaskScheduler(resolveSchedulerBean(this.beanFactory, TaskScheduler.class, true));
}
@ -271,13 +274,19 @@ public class ScheduledAnnotationBeanPostProcessor @@ -271,13 +274,19 @@ public class ScheduledAnnotationBeanPostProcessor
}
}
catch (NoSuchBeanDefinitionException ex) {
logger.trace("Could not find default TaskScheduler bean", ex);
if (logger.isTraceEnabled()) {
logger.trace("Could not find default TaskScheduler bean - attempting to find ScheduledExecutorService: " +
ex.getMessage());
}
// Search for ScheduledExecutorService bean next...
try {
this.registrar.setScheduler(resolveSchedulerBean(this.beanFactory, ScheduledExecutorService.class, false));
}
catch (NoUniqueBeanDefinitionException ex2) {
logger.trace("Could not find unique ScheduledExecutorService bean", ex2);
if (logger.isTraceEnabled()) {
logger.trace("Could not find unique ScheduledExecutorService bean - attempting to resolve by name: " +
ex2.getMessage());
}
try {
this.registrar.setScheduler(resolveSchedulerBean(this.beanFactory, ScheduledExecutorService.class, true));
}
@ -292,7 +301,10 @@ public class ScheduledAnnotationBeanPostProcessor @@ -292,7 +301,10 @@ public class ScheduledAnnotationBeanPostProcessor
}
}
catch (NoSuchBeanDefinitionException ex2) {
logger.trace("Could not find default ScheduledExecutorService bean", ex2);
if (logger.isTraceEnabled()) {
logger.trace("Could not find default ScheduledExecutorService bean - falling back to default: " +
ex2.getMessage());
}
// Giving up -> falling back to default scheduler within the registrar...
logger.info("No TaskScheduler/ScheduledExecutorService bean found for scheduled processing");
}

14
spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@ -312,7 +312,6 @@ public abstract class StatementCreatorUtils { @@ -312,7 +312,6 @@ public abstract class StatementCreatorUtils {
else {
ps.setClob(paramIndex, new StringReader(strVal), strVal.length());
}
return;
}
else {
// Fallback: setString or setNString binding
@ -460,12 +459,17 @@ public abstract class StatementCreatorUtils { @@ -460,12 +459,17 @@ public abstract class StatementCreatorUtils {
public static void cleanupParameters(@Nullable Collection<?> paramValues) {
if (paramValues != null) {
for (Object inValue : paramValues) {
if (inValue instanceof DisposableSqlTypeValue) {
((DisposableSqlTypeValue) inValue).cleanup();
// Unwrap SqlParameterValue first...
if (inValue instanceof SqlParameterValue) {
inValue = ((SqlParameterValue) inValue).getValue();
}
else if (inValue instanceof SqlValue) {
// Check for disposable value types
if (inValue instanceof SqlValue) {
((SqlValue) inValue).cleanup();
}
else if (inValue instanceof DisposableSqlTypeValue) {
((DisposableSqlTypeValue) inValue).cleanup();
}
}
}
}

40
spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.jms.config;
import javax.jms.ConnectionFactory;
import javax.jms.ExceptionListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -48,10 +49,13 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess @@ -48,10 +49,13 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
private DestinationResolver destinationResolver;
@Nullable
private ErrorHandler errorHandler;
private MessageConverter messageConverter;
@Nullable
private MessageConverter messageConverter;
private ExceptionListener exceptionListener;
@Nullable
private ErrorHandler errorHandler;
@Nullable
private Boolean sessionTransacted;
@ -99,17 +103,25 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess @@ -99,17 +103,25 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
}
/**
* @see AbstractMessageListenerContainer#setErrorHandler(ErrorHandler)
* @see AbstractMessageListenerContainer#setMessageConverter(MessageConverter)
*/
public void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
public void setMessageConverter(MessageConverter messageConverter) {
this.messageConverter = messageConverter;
}
/**
* @see AbstractMessageListenerContainer#setMessageConverter(MessageConverter)
* @since 5.2.8
* @see AbstractMessageListenerContainer#setExceptionListener(ExceptionListener)
*/
public void setMessageConverter(MessageConverter messageConverter) {
this.messageConverter = messageConverter;
public void setExceptionListener(ExceptionListener exceptionListener) {
this.exceptionListener = exceptionListener;
}
/**
* @see AbstractMessageListenerContainer#setErrorHandler(ErrorHandler)
*/
public void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
/**
@ -182,6 +194,7 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess @@ -182,6 +194,7 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
this.autoStartup = autoStartup;
}
@Override
public C createListenerContainer(JmsListenerEndpoint endpoint) {
C instance = createContainerInstance();
@ -192,12 +205,15 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess @@ -192,12 +205,15 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
if (this.destinationResolver != null) {
instance.setDestinationResolver(this.destinationResolver);
}
if (this.errorHandler != null) {
instance.setErrorHandler(this.errorHandler);
}
if (this.messageConverter != null) {
instance.setMessageConverter(this.messageConverter);
}
if (this.exceptionListener != null) {
instance.setExceptionListener(this.exceptionListener);
}
if (this.errorHandler != null) {
instance.setErrorHandler(this.errorHandler);
}
if (this.sessionTransacted != null) {
instance.setSessionTransacted(this.sessionTransacted);
}

9
spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java

@ -99,7 +99,7 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { @@ -99,7 +99,7 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
throws ServletException, IOException {
HttpServletResponse responseToUse = response;
if (!isAsyncDispatch(request) && !(response instanceof ContentCachingResponseWrapper)) {
if (!isAsyncDispatch(request) && !(response instanceof ConditionalContentCachingResponseWrapper)) {
responseToUse = new ConditionalContentCachingResponseWrapper(response, request);
}
@ -111,10 +111,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { @@ -111,10 +111,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
}
private void updateResponse(HttpServletRequest request, HttpServletResponse response) throws IOException {
ContentCachingResponseWrapper wrapper =
WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
ConditionalContentCachingResponseWrapper wrapper =
WebUtils.getNativeResponse(response, ConditionalContentCachingResponseWrapper.class);
Assert.notNull(wrapper, "ContentCachingResponseWrapper not found");
HttpServletResponse rawResponse = (HttpServletResponse) wrapper.getResponse();
@ -209,7 +207,6 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { @@ -209,7 +207,6 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
private final HttpServletRequest request;
ConditionalContentCachingResponseWrapper(HttpServletResponse response, HttpServletRequest request) {
super(response);
this.request = request;

Loading…
Cancel
Save