Skip to content

Commit 4549d76

Browse files
committed
Merge from sbrannen/SPR-11512
* SPR-11512: Support annotation attribute aliases and overrides via @AliasFor
2 parents a87d5f8 + ca66e07 commit 4549d76

31 files changed

+1582
-336
lines changed

spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -32,7 +32,6 @@
3232
import org.springframework.jmx.export.metadata.ManagedOperation;
3333
import org.springframework.jmx.export.metadata.ManagedOperationParameter;
3434
import org.springframework.jmx.export.metadata.ManagedResource;
35-
import org.springframework.util.StringUtils;
3635
import org.springframework.util.StringValueResolver;
3736

3837
/**
@@ -66,7 +65,6 @@ public String resolveStringValue(String strVal) {
6665
}
6766
}
6867

69-
7068
@Override
7169
public ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException {
7270
org.springframework.jmx.export.annotation.ManagedResource ann =
@@ -76,13 +74,6 @@ public ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMeta
7674
}
7775
ManagedResource managedResource = new ManagedResource();
7876
AnnotationBeanUtils.copyPropertiesToBean(ann, managedResource, this.embeddedValueResolver);
79-
if (!"".equals(ann.value()) && !StringUtils.hasLength(managedResource.getObjectName())) {
80-
String value = ann.value();
81-
if (this.embeddedValueResolver != null) {
82-
value = this.embeddedValueResolver.resolveStringValue(value);
83-
}
84-
managedResource.setObjectName(value);
85-
}
8677
return managedResource;
8778
}
8879

spring-context/src/main/java/org/springframework/jmx/export/annotation/ManagedResource.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -23,6 +23,8 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import org.springframework.core.annotation.AliasFor;
27+
2628
/**
2729
* JDK 1.5+ class-level annotation that indicates to register instances of a
2830
* class with a JMX server, corresponding to the ManagedResource attribute.
@@ -34,6 +36,7 @@
3436
*
3537
* @author Rob Harrop
3638
* @author Juergen Hoeller
39+
* @author Sam Brannen
3740
* @since 1.2
3841
* @see org.springframework.jmx.export.metadata.ManagedResource
3942
*/
@@ -44,11 +47,12 @@
4447
public @interface ManagedResource {
4548

4649
/**
47-
* The annotation value is equivalent to the {@code objectName}
48-
* attribute, for simple default usage.
50+
* Alias for the {@link #objectName} attribute, for simple default usage.
4951
*/
52+
@AliasFor(attribute = "objectName")
5053
String value() default "";
5154

55+
@AliasFor(attribute = "value")
5256
String objectName() default "";
5357

5458
String description() default "";
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2002-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.core.annotation;
18+
19+
import java.lang.annotation.Annotation;
20+
import java.lang.annotation.Documented;
21+
import java.lang.annotation.ElementType;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
/**
27+
* TODO Document @AliasFor.
28+
*
29+
* @author Sam Brannen
30+
* @since 4.2
31+
*/
32+
@Retention(RetentionPolicy.RUNTIME)
33+
@Target(ElementType.METHOD)
34+
@Documented
35+
public @interface AliasFor {
36+
37+
String attribute();
38+
39+
Class<? extends Annotation> annotation() default Annotation.class;
40+
41+
}

0 commit comments

Comments
 (0)