Polishing
This commit is contained in:
parent
3564616b7f
commit
dd7ddc08ff
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.context.weaving;
|
package org.springframework.context.weaving;
|
||||||
|
|
||||||
|
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.IllegalClassFormatException;
|
import java.lang.instrument.IllegalClassFormatException;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
@ -44,12 +43,13 @@ import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||||
public class AspectJWeavingEnabler
|
public class AspectJWeavingEnabler
|
||||||
implements BeanFactoryPostProcessor, BeanClassLoaderAware, LoadTimeWeaverAware, Ordered {
|
implements BeanFactoryPostProcessor, BeanClassLoaderAware, LoadTimeWeaverAware, Ordered {
|
||||||
|
|
||||||
|
public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml";
|
||||||
|
|
||||||
|
|
||||||
private ClassLoader beanClassLoader;
|
private ClassLoader beanClassLoader;
|
||||||
|
|
||||||
private LoadTimeWeaver loadTimeWeaver;
|
private LoadTimeWeaver loadTimeWeaver;
|
||||||
|
|
||||||
public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml";
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
|
@ -71,6 +71,12 @@ public class AspectJWeavingEnabler
|
||||||
enableAspectJWeaving(this.loadTimeWeaver, this.beanClassLoader);
|
enableAspectJWeaving(this.loadTimeWeaver, this.beanClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable AspectJ weaving with the given {@link LoadTimeWeaver}.
|
||||||
|
* @param weaverToUse the LoadTimeWeaver to apply to (or {@code null} for a default weaver)
|
||||||
|
* @param beanClassLoader the class loader to create a default weaver for (if necessary)
|
||||||
|
*/
|
||||||
public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) {
|
public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) {
|
||||||
if (weaverToUse == null) {
|
if (weaverToUse == null) {
|
||||||
if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
|
if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
|
||||||
|
@ -80,8 +86,8 @@ public class AspectJWeavingEnabler
|
||||||
throw new IllegalStateException("No LoadTimeWeaver available");
|
throw new IllegalStateException("No LoadTimeWeaver available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
weaverToUse.addTransformer(new AspectJClassBypassingClassFileTransformer(
|
weaverToUse.addTransformer(
|
||||||
new ClassPreProcessorAgentAdapter()));
|
new AspectJClassBypassingClassFileTransformer(new ClassPreProcessorAgentAdapter()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,4 +114,5 @@ public class AspectJWeavingEnabler
|
||||||
return this.delegate.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
|
return this.delegate.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -29,15 +29,13 @@ import java.util.Map;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class that encapsulates the specification of a method parameter, i.e.
|
* Helper class that encapsulates the specification of a method parameter, i.e. a {@link Method}
|
||||||
* a {@link Method} or {@link Constructor} plus a parameter index and a nested
|
* or {@link Constructor} plus a parameter index and a nested type index for a declared generic
|
||||||
* type index for a declared generic type. Useful as a specification object to
|
* type. Useful as a specification object to pass along.
|
||||||
* pass along.
|
|
||||||
*
|
*
|
||||||
* <p>As of 4.2, there is a {@link org.springframework.core.annotation.SynthesizingMethodParameter
|
* <p>As of 4.2, there is a {@link org.springframework.core.annotation.SynthesizingMethodParameter}
|
||||||
* SynthesizingMethodParameter} subclass available which synthesizes annotations
|
* subclass available which synthesizes annotations with attribute aliases. That subclass is used
|
||||||
* with attribute aliases. That subclass is used for web and message endpoint
|
* for web and message endpoint processing, in particular.
|
||||||
* processing, in particular.
|
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
@ -167,7 +165,14 @@ public class MethodParameter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the wrapped member.
|
* Return the class that declares the underlying Method or Constructor.
|
||||||
|
*/
|
||||||
|
public Class<?> getDeclaringClass() {
|
||||||
|
return getMember().getDeclaringClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the wrapped member.
|
||||||
* @return the Method or Constructor as Member
|
* @return the Method or Constructor as Member
|
||||||
*/
|
*/
|
||||||
public Member getMember() {
|
public Member getMember() {
|
||||||
|
@ -183,7 +188,9 @@ public class MethodParameter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the wrapped annotated element.
|
* Return the wrapped annotated element.
|
||||||
|
* <p>Note: This method exposes the annotations declared on the method/constructor
|
||||||
|
* itself (i.e. at the method/constructor level, not at the parameter level).
|
||||||
* @return the Method or Constructor as AnnotatedElement
|
* @return the Method or Constructor as AnnotatedElement
|
||||||
*/
|
*/
|
||||||
public AnnotatedElement getAnnotatedElement() {
|
public AnnotatedElement getAnnotatedElement() {
|
||||||
|
@ -198,13 +205,6 @@ public class MethodParameter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the class that declares the underlying Method or Constructor.
|
|
||||||
*/
|
|
||||||
public Class<?> getDeclaringClass() {
|
|
||||||
return getMember().getDeclaringClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the index of the method/constructor parameter.
|
* Return the index of the method/constructor parameter.
|
||||||
* @return the parameter index (-1 in case of the return type)
|
* @return the parameter index (-1 in case of the return type)
|
||||||
|
@ -338,8 +338,8 @@ public class MethodParameter {
|
||||||
/**
|
/**
|
||||||
* Return the nested type of the method/constructor parameter.
|
* Return the nested type of the method/constructor parameter.
|
||||||
* @return the parameter type (never {@code null})
|
* @return the parameter type (never {@code null})
|
||||||
* @see #getNestingLevel()
|
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
* @see #getNestingLevel()
|
||||||
*/
|
*/
|
||||||
public Class<?> getNestedParameterType() {
|
public Class<?> getNestedParameterType() {
|
||||||
if (this.nestingLevel > 1) {
|
if (this.nestingLevel > 1) {
|
||||||
|
@ -370,8 +370,8 @@ public class MethodParameter {
|
||||||
/**
|
/**
|
||||||
* Return the nested generic type of the method/constructor parameter.
|
* Return the nested generic type of the method/constructor parameter.
|
||||||
* @return the parameter type (never {@code null})
|
* @return the parameter type (never {@code null})
|
||||||
* @see #getNestingLevel()
|
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
|
* @see #getNestingLevel()
|
||||||
*/
|
*/
|
||||||
public Type getNestedGenericParameterType() {
|
public Type getNestedGenericParameterType() {
|
||||||
if (this.nestingLevel > 1) {
|
if (this.nestingLevel > 1) {
|
||||||
|
@ -424,32 +424,36 @@ public class MethodParameter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the parameter annotation of the given type, if available.
|
* Return {@code true} if the parameter has at least one annotation,
|
||||||
* @param annotationType the annotation type to look for
|
* {@code false} if it has none.
|
||||||
* @return the annotation object, or {@code null} if not found
|
* @see #getParameterAnnotations()
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T extends Annotation> T getParameterAnnotation(Class<T> annotationType) {
|
|
||||||
Annotation[] anns = getParameterAnnotations();
|
|
||||||
for (Annotation ann : anns) {
|
|
||||||
if (annotationType.isInstance(ann)) {
|
|
||||||
return (T) ann;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the parameter has at least one annotation, false if it has none.
|
|
||||||
*/
|
*/
|
||||||
public boolean hasParameterAnnotations() {
|
public boolean hasParameterAnnotations() {
|
||||||
return (getParameterAnnotations().length != 0);
|
return (getParameterAnnotations().length != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the parameter has the given annotation type, and false if it doesn't.
|
* Return the parameter annotation of the given type, if available.
|
||||||
|
* @param annotationType the annotation type to look for
|
||||||
|
* @return the annotation object, or {@code null} if not found
|
||||||
*/
|
*/
|
||||||
public <T extends Annotation> boolean hasParameterAnnotation(Class<T> annotationType) {
|
@SuppressWarnings("unchecked")
|
||||||
|
public <A extends Annotation> A getParameterAnnotation(Class<A> annotationType) {
|
||||||
|
Annotation[] anns = getParameterAnnotations();
|
||||||
|
for (Annotation ann : anns) {
|
||||||
|
if (annotationType.isInstance(ann)) {
|
||||||
|
return (A) ann;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the parameter is declared with the given annotation type.
|
||||||
|
* @param annotationType the annotation type to look for
|
||||||
|
* @see #getParameterAnnotation(Class)
|
||||||
|
*/
|
||||||
|
public <A extends Annotation> boolean hasParameterAnnotation(Class<A> annotationType) {
|
||||||
return (getParameterAnnotation(annotationType) != null);
|
return (getParameterAnnotation(annotationType) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -64,11 +64,11 @@ public interface ConversionService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the given {@code source} to the specified {@code targetType}.
|
* Convert the given {@code source} to the specified {@code targetType}.
|
||||||
* @param source the source object to convert (may be null)
|
* @param source the source object to convert (may be {@code null})
|
||||||
* @param targetType the target type to convert to (required)
|
* @param targetType the target type to convert to (required)
|
||||||
* @return the converted object, an instance of targetType
|
* @return the converted object, an instance of targetType
|
||||||
* @throws ConversionException if a conversion exception occurred
|
* @throws ConversionException if a conversion exception occurred
|
||||||
* @throws IllegalArgumentException if targetType is null
|
* @throws IllegalArgumentException if targetType is {@code null}
|
||||||
*/
|
*/
|
||||||
<T> T convert(Object source, Class<T> targetType);
|
<T> T convert(Object source, Class<T> targetType);
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public interface ConversionService {
|
||||||
* Convert the given {@code source} to the specified {@code targetType}.
|
* Convert the given {@code source} to the specified {@code targetType}.
|
||||||
* The TypeDescriptors provide additional context about the source and target locations
|
* The TypeDescriptors provide additional context about the source and target locations
|
||||||
* where conversion will occur, often object fields or property locations.
|
* where conversion will occur, often object fields or property locations.
|
||||||
* @param source the source object to convert (may be null)
|
* @param source the source object to convert (may be {@code null})
|
||||||
* @param sourceType context about the source type to convert from
|
* @param sourceType context about the source type to convert from
|
||||||
* (may be {@code null} if source is {@code null})
|
* (may be {@code null} if source is {@code null})
|
||||||
* @param targetType context about the target type to convert to (required)
|
* @param targetType context about the target type to convert to (required)
|
||||||
|
|
|
@ -69,9 +69,9 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||||
* and services which use plain JDBC (without being aware of Hibernate)!
|
* and services which use plain JDBC (without being aware of Hibernate)!
|
||||||
* Application code needs to stick to the same simple Connection lookup pattern as
|
* Application code needs to stick to the same simple Connection lookup pattern as
|
||||||
* with {@link org.springframework.jdbc.datasource.DataSourceTransactionManager}
|
* with {@link org.springframework.jdbc.datasource.DataSourceTransactionManager}
|
||||||
* (i.e. {@link DataSourceUtils#getConnection}
|
* (i.e. {@link org.springframework.jdbc.datasource.DataSourceUtils#getConnection}
|
||||||
* or going through a
|
* or going through a
|
||||||
* {@link TransactionAwareDataSourceProxy}).
|
* {@link org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy}).
|
||||||
*
|
*
|
||||||
* <p>Note: To be able to register a DataSource's Connection for plain JDBC code,
|
* <p>Note: To be able to register a DataSource's Connection for plain JDBC code,
|
||||||
* this instance needs to be aware of the DataSource ({@link #setDataSource}).
|
* this instance needs to be aware of the DataSource ({@link #setDataSource}).
|
||||||
|
@ -235,7 +235,6 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
||||||
* <p>Default is "false". Turning this flag on enforces over-commit holdability on the
|
* <p>Default is "false". Turning this flag on enforces over-commit holdability on the
|
||||||
* underlying JDBC Connection (if {@link #prepareConnection "prepareConnection"} is on)
|
* underlying JDBC Connection (if {@link #prepareConnection "prepareConnection"} is on)
|
||||||
* and skips the disconnect-on-completion step.
|
* and skips the disconnect-on-completion step.
|
||||||
* @since 4.2
|
|
||||||
* @see Connection#setHoldability
|
* @see Connection#setHoldability
|
||||||
* @see ResultSet#HOLD_CURSORS_OVER_COMMIT
|
* @see ResultSet#HOLD_CURSORS_OVER_COMMIT
|
||||||
* @see #disconnectOnCompletion(Session)
|
* @see #disconnectOnCompletion(Session)
|
||||||
|
@ -687,7 +686,6 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
|
||||||
* <p>The default implementation simply calls {@link Session#disconnect()}.
|
* <p>The default implementation simply calls {@link Session#disconnect()}.
|
||||||
* Subclasses may override this with a no-op or with fine-tuned disconnection logic.
|
* Subclasses may override this with a no-op or with fine-tuned disconnection logic.
|
||||||
* @param session the Hibernate Session to disconnect
|
* @param session the Hibernate Session to disconnect
|
||||||
* @since 4.2
|
|
||||||
* @see Session#disconnect()
|
* @see Session#disconnect()
|
||||||
*/
|
*/
|
||||||
protected void disconnectOnCompletion(Session session) {
|
protected void disconnectOnCompletion(Session session) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -33,8 +33,8 @@ import org.springframework.web.method.HandlerMethod;
|
||||||
* or common handler behavior like locale or theme changes. Its main purpose
|
* or common handler behavior like locale or theme changes. Its main purpose
|
||||||
* is to allow for factoring out repetitive handler code.
|
* is to allow for factoring out repetitive handler code.
|
||||||
*
|
*
|
||||||
* <p>In an async processing scenario, the handler may be executed in a separate
|
* <p>In an asynchronous processing scenario, the handler may be executed in a
|
||||||
* thread while the main thread exits without rendering or invoking the
|
* separate thread while the main thread exits without rendering or invoking the
|
||||||
* {@code postHandle} and {@code afterCompletion} callbacks. When concurrent
|
* {@code postHandle} and {@code afterCompletion} callbacks. When concurrent
|
||||||
* handler execution completes, the request is dispatched back in order to
|
* handler execution completes, the request is dispatched back in order to
|
||||||
* proceed with rendering the model and all methods of this contract are invoked
|
* proceed with rendering the model and all methods of this contract are invoked
|
||||||
|
@ -77,16 +77,13 @@ public interface HandlerInterceptor {
|
||||||
/**
|
/**
|
||||||
* Intercept the execution of a handler. Called after HandlerMapping determined
|
* Intercept the execution of a handler. Called after HandlerMapping determined
|
||||||
* an appropriate handler object, but before HandlerAdapter invokes the handler.
|
* an appropriate handler object, but before HandlerAdapter invokes the handler.
|
||||||
*
|
|
||||||
* <p>DispatcherServlet processes a handler in an execution chain, consisting
|
* <p>DispatcherServlet processes a handler in an execution chain, consisting
|
||||||
* of any number of interceptors, with the handler itself at the end.
|
* of any number of interceptors, with the handler itself at the end.
|
||||||
* With this method, each interceptor can decide to abort the execution chain,
|
* With this method, each interceptor can decide to abort the execution chain,
|
||||||
* typically sending a HTTP error or writing a custom response.
|
* typically sending a HTTP error or writing a custom response.
|
||||||
*
|
|
||||||
* <p><strong>Note:</strong> special considerations apply for asynchronous
|
* <p><strong>Note:</strong> special considerations apply for asynchronous
|
||||||
* request processing. For more details see
|
* request processing. For more details see
|
||||||
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
|
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
|
||||||
*
|
|
||||||
* @param request current HTTP request
|
* @param request current HTTP request
|
||||||
* @param response current HTTP response
|
* @param response current HTTP response
|
||||||
* @param handler chosen handler to execute, for type and/or instance evaluation
|
* @param handler chosen handler to execute, for type and/or instance evaluation
|
||||||
|
@ -102,19 +99,16 @@ public interface HandlerInterceptor {
|
||||||
* Intercept the execution of a handler. Called after HandlerAdapter actually
|
* Intercept the execution of a handler. Called after HandlerAdapter actually
|
||||||
* invoked the handler, but before the DispatcherServlet renders the view.
|
* invoked the handler, but before the DispatcherServlet renders the view.
|
||||||
* Can expose additional model objects to the view via the given ModelAndView.
|
* Can expose additional model objects to the view via the given ModelAndView.
|
||||||
*
|
|
||||||
* <p>DispatcherServlet processes a handler in an execution chain, consisting
|
* <p>DispatcherServlet processes a handler in an execution chain, consisting
|
||||||
* of any number of interceptors, with the handler itself at the end.
|
* of any number of interceptors, with the handler itself at the end.
|
||||||
* With this method, each interceptor can post-process an execution,
|
* With this method, each interceptor can post-process an execution,
|
||||||
* getting applied in inverse order of the execution chain.
|
* getting applied in inverse order of the execution chain.
|
||||||
*
|
|
||||||
* <p><strong>Note:</strong> special considerations apply for asynchronous
|
* <p><strong>Note:</strong> special considerations apply for asynchronous
|
||||||
* request processing. For more details see
|
* request processing. For more details see
|
||||||
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
|
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
|
||||||
*
|
|
||||||
* @param request current HTTP request
|
* @param request current HTTP request
|
||||||
* @param response current HTTP response
|
* @param response current HTTP response
|
||||||
* @param handler handler (or {@link HandlerMethod}) that started async
|
* @param handler handler (or {@link HandlerMethod}) that started asynchronous
|
||||||
* execution, for type and/or instance examination
|
* execution, for type and/or instance examination
|
||||||
* @param modelAndView the {@code ModelAndView} that the handler returned
|
* @param modelAndView the {@code ModelAndView} that the handler returned
|
||||||
* (can also be {@code null})
|
* (can also be {@code null})
|
||||||
|
@ -127,21 +121,17 @@ public interface HandlerInterceptor {
|
||||||
* Callback after completion of request processing, that is, after rendering
|
* Callback after completion of request processing, that is, after rendering
|
||||||
* the view. Will be called on any outcome of handler execution, thus allows
|
* the view. Will be called on any outcome of handler execution, thus allows
|
||||||
* for proper resource cleanup.
|
* for proper resource cleanup.
|
||||||
*
|
|
||||||
* <p>Note: Will only be called if this interceptor's {@code preHandle}
|
* <p>Note: Will only be called if this interceptor's {@code preHandle}
|
||||||
* method has successfully completed and returned {@code true}!
|
* method has successfully completed and returned {@code true}!
|
||||||
*
|
|
||||||
* <p>As with the {@code postHandle} method, the method will be invoked on each
|
* <p>As with the {@code postHandle} method, the method will be invoked on each
|
||||||
* interceptor in the chain in reverse order, so the first interceptor will be
|
* interceptor in the chain in reverse order, so the first interceptor will be
|
||||||
* the last to be invoked.
|
* the last to be invoked.
|
||||||
*
|
|
||||||
* <p><strong>Note:</strong> special considerations apply for asynchronous
|
* <p><strong>Note:</strong> special considerations apply for asynchronous
|
||||||
* request processing. For more details see
|
* request processing. For more details see
|
||||||
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
|
* {@link org.springframework.web.servlet.AsyncHandlerInterceptor}.
|
||||||
*
|
|
||||||
* @param request current HTTP request
|
* @param request current HTTP request
|
||||||
* @param response current HTTP response
|
* @param response current HTTP response
|
||||||
* @param handler handler (or {@link HandlerMethod}) that started async
|
* @param handler handler (or {@link HandlerMethod}) that started asynchronous
|
||||||
* execution, for type and/or instance examination
|
* execution, for type and/or instance examination
|
||||||
* @param ex exception thrown on handler execution, if any
|
* @param ex exception thrown on handler execution, if any
|
||||||
* @throws Exception in case of errors
|
* @throws Exception in case of errors
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -34,7 +34,7 @@ public abstract class AbstractHandlerMethodExceptionResolver extends AbstractHan
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the handler is a {@link HandlerMethod} and then delegates to the
|
* Checks if the handler is a {@link HandlerMethod} and then delegates to the
|
||||||
* base class implementation of {@link #shouldApplyTo(HttpServletRequest, Object)}
|
* base class implementation of {@code #shouldApplyTo(HttpServletRequest, Object)}
|
||||||
* passing the bean of the {@code HandlerMethod}. Otherwise returns {@code false}.
|
* passing the bean of the {@code HandlerMethod}. Otherwise returns {@code false}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,8 +54,7 @@ public abstract class AbstractHandlerMethodExceptionResolver extends AbstractHan
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final ModelAndView doResolveException(
|
protected final ModelAndView doResolveException(
|
||||||
HttpServletRequest request, HttpServletResponse response,
|
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||||
Object handler, Exception ex) {
|
|
||||||
|
|
||||||
return doResolveHandlerMethodException(request, response, (HandlerMethod) handler, ex);
|
return doResolveHandlerMethodException(request, response, (HandlerMethod) handler, ex);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +74,6 @@ public abstract class AbstractHandlerMethodExceptionResolver extends AbstractHan
|
||||||
* @return a corresponding ModelAndView to forward to, or {@code null} for default processing
|
* @return a corresponding ModelAndView to forward to, or {@code null} for default processing
|
||||||
*/
|
*/
|
||||||
protected abstract ModelAndView doResolveHandlerMethodException(
|
protected abstract ModelAndView doResolveHandlerMethodException(
|
||||||
HttpServletRequest request, HttpServletResponse response,
|
HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception ex);
|
||||||
HandlerMethod handlerMethod, Exception ex);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -95,7 +95,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
|
||||||
|
|
||||||
public ExceptionHandlerExceptionResolver() {
|
public ExceptionHandlerExceptionResolver() {
|
||||||
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
|
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
|
||||||
stringHttpMessageConverter.setWriteAcceptCharset(false); // See SPR-7316
|
stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316
|
||||||
|
|
||||||
this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
|
this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
|
||||||
this.messageConverters.add(new ByteArrayHttpMessageConverter());
|
this.messageConverters.add(new ByteArrayHttpMessageConverter());
|
||||||
|
@ -264,11 +264,15 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
|
||||||
ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(adviceBean.getBeanType());
|
ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(adviceBean.getBeanType());
|
||||||
if (resolver.hasExceptionMappings()) {
|
if (resolver.hasExceptionMappings()) {
|
||||||
this.exceptionHandlerAdviceCache.put(adviceBean, resolver);
|
this.exceptionHandlerAdviceCache.put(adviceBean, resolver);
|
||||||
logger.info("Detected @ExceptionHandler methods in " + adviceBean);
|
if (logger.isInfoEnabled()) {
|
||||||
|
logger.info("Detected @ExceptionHandler methods in " + adviceBean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ResponseBodyAdvice.class.isAssignableFrom(adviceBean.getBeanType())) {
|
if (ResponseBodyAdvice.class.isAssignableFrom(adviceBean.getBeanType())) {
|
||||||
this.responseBodyAdvice.add(adviceBean);
|
this.responseBodyAdvice.add(adviceBean);
|
||||||
logger.info("Detected ResponseBodyAdvice implementation in " + adviceBean);
|
if (logger.isInfoEnabled()) {
|
||||||
|
logger.info("Detected ResponseBodyAdvice implementation in " + adviceBean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue