Skip to content

Commit 6710c05

Browse files
committed
Document DeprecatedConfigurationProperty
Closes gh-5118
1 parent a1fefb1 commit 6710c05

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

spring-boot-docs/src/main/asciidoc/appendix-configuration-metadata.adoc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,40 @@ the `deprecation` element. This is still supported in a deprecated fashion and s
222222
be used. If no reason and replacement are available, an empty `deprecation` object should be
223223
set.
224224

225+
Deprecation can also be specified declaratively in code by adding the
226+
`@DeprecatedConfigurationProperty` annotation to the getter exposing the deprecated
227+
property. For instance, let's assume the `app.foo.target` property was confusing and
228+
was renamed to `app.foo.name`
229+
230+
[source,java,indent=0]
231+
----
232+
@ConfigurationProperties("app.foo")
233+
public class FooProperties {
234+
235+
private String name;
236+
237+
public String getName() { ... }
238+
239+
public void setName(String name) { ... }
240+
241+
@DeprecatedConfigurationProperty(replacement = "app.foo.name")
242+
@Deprecated
243+
public String getTarget() {
244+
return getName();
245+
}
246+
247+
@Deprecated
248+
public void setTarget(String target) {
249+
setName(target);
250+
}
251+
}
252+
----
253+
254+
The code above makes sure that the deprecated property still works (delegating
255+
to the `name` property behind the scenes). Once the `getTarget` and `setTarget`
256+
methods can be removed from your public API, the automatic deprecation hint in the
257+
meta-data will go away as well.
258+
225259

226260
[[configuration-metadata-hints-attributes]]
227261
==== Hint Attributes

0 commit comments

Comments
 (0)