1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ package io .microsphere .spring .boot .context .properties .annotation ;
19+
20+ import io .microsphere .spring .beans .BeanSource ;
21+ import io .microsphere .spring .boot .context .properties .ListenableConfigurationPropertiesBindHandlerAdvisor ;
22+ import io .microsphere .spring .boot .context .properties .bind .BindListener ;
23+ import io .microsphere .spring .boot .context .properties .bind .ConfigurationPropertiesBeanPropertyChangedEvent ;
24+ import io .microsphere .spring .boot .context .properties .bind .EventPublishingConfigurationPropertiesBeanPropertyChangedListener ;
25+ import io .microsphere .spring .context .annotation .OverrideAnnotationAttributes ;
26+ import org .springframework .boot .context .properties .ConfigurationPropertiesBindHandlerAdvisor ;
27+ import org .springframework .boot .context .properties .EnableConfigurationProperties ;
28+ import org .springframework .boot .context .properties .bind .BindHandler ;
29+ import org .springframework .boot .context .properties .bind .Binder ;
30+ import org .springframework .context .annotation .Import ;
31+
32+ import java .lang .annotation .Documented ;
33+ import java .lang .annotation .Retention ;
34+ import java .lang .annotation .Target ;
35+
36+ import static io .microsphere .spring .beans .BeanSource .BEAN_FACTORY ;
37+ import static io .microsphere .spring .beans .BeanSource .JAVA_SERVICE_PROVIDER ;
38+ import static io .microsphere .spring .beans .BeanSource .SPRING_FACTORIES ;
39+ import static java .lang .annotation .ElementType .TYPE ;
40+ import static java .lang .annotation .RetentionPolicy .RUNTIME ;
41+
42+
43+ /**
44+ * An extension annotation of {@link EnableConfigurationProperties @EnableConfigurationProperties} that provides
45+ * advanced configuration properties binding features.
46+ * <p>
47+ * This annotation enables:
48+ * <ul>
49+ * <li>Automatic advising of {@link BindListener} implementations during {@link Binder#bind(String, Class) binding}</li>
50+ * <li>Event publishing for configuration properties bean property changes (e.g., {@link ConfigurationPropertiesBeanPropertyChangedEvent})</li>
51+ * <li>Flexible bean source configuration for discovering extension components</li>
52+ * </ul>
53+ *
54+ * <h3>Example Usage</h3>
55+ * <pre>{@code
56+ * @Configuration
57+ * @EnableConfigurationPropertiesExtension(
58+ * adviseBindListener = true,
59+ * publishEvents = true,
60+ * sources = {BeanSource.BEAN_FACTORY, BeanSource.SPRING_FACTORIES}
61+ * )
62+ * public class MyConfiguration {
63+ *
64+ * @Bean
65+ * public BindListener myBindListener() {
66+ * return event -> {
67+ * // Handle bind events
68+ * };
69+ * }
70+ * }
71+ * }</pre>
72+ *
73+ * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
74+ * @see EnableConfigurationProperties
75+ * @see OverrideAnnotationAttributes
76+ * @see ListenableConfigurationPropertiesBindHandlerAdvisor
77+ * @see BindListener
78+ * @see ConfigurationPropertiesBindHandlerAdvisor
79+ * @see BindHandler
80+ * @since 1.0.0
81+ */
82+ @ Target (TYPE )
83+ @ Retention (RUNTIME )
84+ @ Documented
85+ @ OverrideAnnotationAttributes
86+ @ Import (EnableConfigurationPropertiesExtensionRegistrar .class )
87+ public @interface EnableConfigurationPropertiesExtension {
88+
89+ /**
90+ * Indicate whether advise {@link BindListener} adapting on the lifecycle of {@link BindHandler} when
91+ * {@link EnableConfigurationProperties @EnableConfigurationProperties} {@link Binder#bind(String, Class) binds}.
92+ *
93+ * @return {@code true} as default
94+ * @see BindListener
95+ * @see ListenableConfigurationPropertiesBindHandlerAdvisor
96+ * @see ConfigurationPropertiesBindHandlerAdvisor
97+ * @see BindHandler
98+ */
99+ boolean adviseBindListener () default true ;
100+
101+ /**
102+ * Indicate whether publish events when {@link EnableConfigurationProperties @EnableConfigurationProperties}
103+ * {@link Binder#bind(String, Class) binds}, such as:
104+ * <ul>
105+ * <li>{@link ConfigurationPropertiesBeanPropertyChangedEvent}</li>
106+ * </ul>
107+ * <p>
108+ * If {@link #adviseBindListener()} is {@code false}, the events will not be published.
109+ *
110+ * @return {@code true} as default
111+ * @see #adviseBindListener()
112+ * @see ConfigurationPropertiesBeanPropertyChangedEvent
113+ * @see EventPublishingConfigurationPropertiesBeanPropertyChangedListener
114+ * @see ListenableConfigurationPropertiesBindHandlerAdvisor
115+ */
116+ boolean publishEvents () default true ;
117+
118+ /**
119+ * Indicate the sources of beans from which the {@link EnableConfigurationProperties @EnableConfigurationProperties}
120+ * extension components are collected, such as:
121+ * <ul>
122+ * <li>{@link ConfigurationPropertiesBindHandlerAdvisor}</li>
123+ * <li>{@link BindListener}</li>
124+ * </ul>
125+ *
126+ * @return the default value is the array of
127+ * {@link BeanSource#BEAN_FACTORY}, {@link BeanSource#SPRING_FACTORIES} and {@link BeanSource#JAVA_SERVICE_PROVIDER}
128+ * @see BeanSource#BEAN_FACTORY
129+ * @see BeanSource#SPRING_FACTORIES
130+ * @see BeanSource#JAVA_SERVICE_PROVIDER
131+ */
132+ BeanSource [] sources () default {BEAN_FACTORY , SPRING_FACTORIES , JAVA_SERVICE_PROVIDER };
133+ }
0 commit comments