Skip to content

Commit d5408c0

Browse files
committed
Introduce @proxyable annotation for bean-specific proxy type
Closes gh-35296 See gh-35293
1 parent df86a99 commit d5408c0

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2002-present 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+
* https://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.context.annotation;
18+
19+
/**
20+
* Common enum for indicating a desired proxy type.
21+
*
22+
* @author Juergen Hoeller
23+
* @since 7.0
24+
* @see Proxyable#value()
25+
*/
26+
public enum ProxyType {
27+
28+
/**
29+
* Default is a JDK dynamic proxy, or potentially a class-based CGLIB proxy
30+
* when globally configured.
31+
*/
32+
DEFAULT,
33+
34+
/**
35+
* Suggest a JDK dynamic proxy implementing <i>all</i> interfaces exposed by
36+
* the class of the target object. Overrides a globally configured default.
37+
*/
38+
INTERFACES,
39+
40+
/**
41+
* Suggest a class-based CGLIB proxy. Overrides a globally configured default.
42+
*/
43+
TARGET_CLASS
44+
45+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2002-present 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+
* https://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.context.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
/**
26+
* Common annotation for suggesting a specific proxy type for a {@link Bean @Bean}
27+
* method or {@link org.springframework.stereotype.Component @Component} class,
28+
* overriding a globally configured default.
29+
*
30+
* <p>Only actually applying in case of a bean actually getting auto-proxied in
31+
* the first place. Actual auto-proxying is dependent on external configuration.
32+
*
33+
* @author Juergen Hoeller
34+
* @since 7.0
35+
* @see org.springframework.aop.framework.autoproxy.AutoProxyUtils#PRESERVE_TARGET_CLASS_ATTRIBUTE
36+
* @see org.springframework.aop.framework.autoproxy.AutoProxyUtils#EXPOSED_INTERFACES_ATTRIBUTE
37+
*/
38+
@Target({ElementType.TYPE, ElementType.METHOD})
39+
@Retention(RetentionPolicy.RUNTIME)
40+
@Documented
41+
public @interface Proxyable {
42+
43+
/**
44+
* Suggest a specific proxy type, either {@link ProxyType#INTERFACES} for
45+
* a JDK dynamic proxy or {@link ProxyType#TARGET_CLASS} for a CGLIB proxy,
46+
* overriding a globally configured default.
47+
*/
48+
ProxyType value() default ProxyType.DEFAULT;
49+
50+
/**
51+
* Suggest a JDK dynamic proxy with specific interfaces to expose, overriding
52+
* a globally configured default.
53+
* <p>Only taken into account if {@link #value()} is not {@link ProxyType#TARGET_CLASS}.
54+
*/
55+
Class<?>[] interfaces() default {};
56+
57+
58+
}

0 commit comments

Comments
 (0)