Optimized access to resolved bean type (avoiding BeanFactory locks)

Revised HandlerMethod.getBeanType() impl for both web and messaging.
In addition, HandlerMethods get created with the internal BeanFactory now.

Issue: SPR-12832
This commit is contained in:
Juergen Hoeller
2015-03-20 17:35:44 +01:00
parent ab771dfd97
commit 898c24fcdd
4 changed files with 100 additions and 93 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@@ -40,8 +40,8 @@ import org.springframework.web.method.HandlerMethodSelector;
import org.springframework.web.servlet.HandlerMapping;
/**
* Abstract base class for {@link HandlerMapping} implementations that define a
* mapping between a request and a {@link HandlerMethod}.
* Abstract base class for {@link HandlerMapping} implementations that define
* a mapping between a request and a {@link HandlerMethod}.
*
* <p>For each registered handler method, a unique mapping is maintained with
* subclasses defining the details of the mapping type {@code <T>}.
@@ -73,7 +73,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
private HandlerMethodMappingNamingStrategy<T> namingStrategy;
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<T, HandlerMethod>();
private final MultiValueMap<String, T> urlMap = new LinkedMultiValueMap<String, T>();
@@ -96,8 +95,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
/**
* Configure the naming strategy to use for assigning a default name to every
* mapped handler method.
*
* @param namingStrategy strategy to use.
*/
public void setHandlerMethodMappingNamingStrategy(HandlerMethodMappingNamingStrategy<T> namingStrategy) {
this.namingStrategy = namingStrategy;
@@ -118,6 +115,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
return this.nameMap.get(mappingName);
}
/**
* Detects handler methods at initialization.
*/
@@ -234,7 +232,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
}
private void updateNameMap(String name, HandlerMethod newHandlerMethod) {
List<HandlerMethod> handlerMethods = this.nameMap.get(name);
if (handlerMethods != null) {
for (HandlerMethod handlerMethod : handlerMethods) {
@@ -266,7 +263,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
HandlerMethod handlerMethod;
if (handler instanceof String) {
String beanName = (String) handler;
handlerMethod = new HandlerMethod(beanName, getApplicationContext(), method);
handlerMethod = new HandlerMethod(beanName,
getApplicationContext().getAutowireCapableBeanFactory(), method);
}
else {
handlerMethod = new HandlerMethod(handler, method);
@@ -375,7 +373,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
* Return a comparator for sorting matching mappings.
* The returned comparator should sort 'better' matches higher.
* @param request the current request
* @return the comparator, never {@code null}
* @return the comparator (never {@code null})
*/
protected abstract Comparator<T> getMappingComparator(HttpServletRequest request);