Skip to content

Commit b79e8a5

Browse files
committed
Support for Common Annotations 1.1 Resource.lookup() attribute
Issue: SPR-13941
1 parent 268ebd7 commit b79e8a5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -140,6 +140,9 @@
140140
public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBeanPostProcessor
141141
implements InstantiationAwareBeanPostProcessor, BeanFactoryAware, Serializable {
142142

143+
// Common Annotations 1.1 Resource.lookup() available? Not present on JDK 6...
144+
private static final Method lookupAttribute = ClassUtils.getMethodIfAvailable(Resource.class, "lookup");
145+
143146
private static Class<? extends Annotation> webServiceRefClass = null;
144147

145148
private static Class<? extends Annotation> ejbRefClass = null;
@@ -604,7 +607,9 @@ else if (beanFactory instanceof ConfigurableBeanFactory){
604607
}
605608
this.name = resourceName;
606609
this.lookupType = resourceType;
607-
this.mappedName = resource.mappedName();
610+
String lookupValue = (lookupAttribute != null ?
611+
(String) ReflectionUtils.invokeMethod(lookupAttribute, resource) : null);
612+
this.mappedName = (StringUtils.hasLength(lookupValue) ? lookupValue : resource.mappedName());
608613
Lazy lazy = ae.getAnnotation(Lazy.class);
609614
this.lazyLookup = (lazy != null && lazy.value());
610615
}

0 commit comments

Comments
 (0)