From 94050b36386c8536aa2afc27aab4d099039702ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 8 Apr 2024 11:53:56 +0200 Subject: [PATCH] Use code includes and tabs in SpEL documentation See gh-22171 --- .../ROOT/pages/core/expressions/beandef.adoc | 205 +----------------- .../CustomerPreferenceDao.java | 20 ++ .../FieldValueTestBean.java | 35 +++ .../expressionsbeandef/MovieFinder.java | 20 ++ .../expressionsbeandef/MovieRecommender.java | 36 +++ .../expressionsbeandef/NumberGuess.java | 36 +++ .../PropertyValueTestBean.java | 35 +++ .../expressionsbeandef/ShapeGuess.java | 35 +++ .../expressionsbeandef/SimpleMovieLister.java | 37 ++++ .../expressionsbeandef/FieldValueTestBean.kt | 27 +++ .../expressionsbeandef/MovieRecommender.kt | 27 +++ .../expressionsbeandef/NumberGuess.kt | 27 +++ .../PropertyValueTestBean.kt | 27 +++ .../expressionsbeandef/ShapeGuess.kt | 27 +++ .../expressionsbeandef/SimpleMovieLister.kt | 37 ++++ .../expressionsbeandef/MovieRecommender.xml | 14 ++ .../PropertyValueTestBean.xml | 13 ++ .../expressionsbeandef/ShapeGuess.xml | 13 ++ 18 files changed, 476 insertions(+), 195 deletions(-) create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/CustomerPreferenceDao.java create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.java create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieFinder.java create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.java create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.java create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.java create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.java create mode 100644 framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.java create mode 100644 framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.kt create mode 100644 framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.kt create mode 100644 framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.kt create mode 100644 framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.kt create mode 100644 framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.kt create mode 100644 framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.kt create mode 100644 framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.xml create mode 100644 framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.xml create mode 100644 framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.xml diff --git a/framework-docs/modules/ROOT/pages/core/expressions/beandef.adoc b/framework-docs/modules/ROOT/pages/core/expressions/beandef.adoc index 7617ab15ef..a246534089 100644 --- a/framework-docs/modules/ROOT/pages/core/expressions/beandef.adoc +++ b/framework-docs/modules/ROOT/pages/core/expressions/beandef.adoc @@ -1,219 +1,34 @@ [[expressions-beandef]] = Expressions in Bean Definitions -You can use SpEL expressions with XML-based or annotation-based configuration metadata for -defining `BeanDefinition` instances. In both cases, the syntax to define the expression is of the -form `#{ }`. - - - -[[expressions-beandef-xml-based]] -== XML Configuration - -A property or constructor argument value can be set by using expressions, as the following -example shows: - -[source,xml,indent=0,subs="verbatim"] ----- - - - - - ----- +You can use SpEL expressions with configuration metadata for defining bean instances. In both +cases, the syntax to define the expression is of the form `#{ }`. All beans in the application context are available as predefined variables with their common bean name. This includes standard context beans such as `environment` (of type `org.springframework.core.env.Environment`) as well as `systemProperties` and `systemEnvironment` (of type `Map`) for access to the runtime environment. -The following example shows access to the `systemProperties` bean as a SpEL variable: - -[source,xml,indent=0,subs="verbatim"] ----- - - - - - ----- - -Note that you do not have to prefix the predefined variable with the `#` symbol here. - -You can also refer to other bean properties by name, as the following example shows: - -[source,xml,indent=0,subs="verbatim"] ----- - - - - - - - - - - - ----- - - - -[[expressions-beandef-annotation-based]] -== Annotation Configuration - To specify a default value, you can place the `@Value` annotation on fields, methods, -and method or constructor parameters. +and method or constructor parameters (or XML equivalent). The following example sets the default value of a field: -[tabs] -====== -Java:: -+ -[source,java,indent=0,subs="verbatim,quotes",role="primary"] ----- - public class FieldValueTestBean { +include-code::./FieldValueTestBean[tag=snippet,indent=0] - @Value("#{ systemProperties['user.region'] }") - private String defaultLocale; - - public void setDefaultLocale(String defaultLocale) { - this.defaultLocale = defaultLocale; - } - - public String getDefaultLocale() { - return this.defaultLocale; - } - } ----- - -Kotlin:: -+ -[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] ----- - class FieldValueTestBean { - - @Value("#{ systemProperties['user.region'] }") - var defaultLocale: String? = null - } ----- -====== +Note that you do not have to prefix the predefined variable with the `#` symbol here. The following example shows the equivalent but on a property setter method: -[tabs] -====== -Java:: -+ -[source,java,indent=0,subs="verbatim,quotes",role="primary"] ----- - public class PropertyValueTestBean { - - private String defaultLocale; - - @Value("#{ systemProperties['user.region'] }") - public void setDefaultLocale(String defaultLocale) { - this.defaultLocale = defaultLocale; - } - - public String getDefaultLocale() { - return this.defaultLocale; - } - } ----- - -Kotlin:: -+ -[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] ----- - class PropertyValueTestBean { - - @Value("#{ systemProperties['user.region'] }") - var defaultLocale: String? = null - } ----- -====== +include-code::./PropertyValueTestBean[tag=snippet,indent=0] Autowired methods and constructors can also use the `@Value` annotation, as the following examples show: -[tabs] -====== -Java:: -+ -[source,java,indent=0,subs="verbatim,quotes",role="primary"] ----- - public class SimpleMovieLister { - - private MovieFinder movieFinder; - private String defaultLocale; - - @Autowired - public void configure(MovieFinder movieFinder, - @Value("#{ systemProperties['user.region'] }") String defaultLocale) { - this.movieFinder = movieFinder; - this.defaultLocale = defaultLocale; - } - - // ... - } ----- - -Kotlin:: -+ -[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] ----- - class SimpleMovieLister { - - private lateinit var movieFinder: MovieFinder - private lateinit var defaultLocale: String - - @Autowired - fun configure(movieFinder: MovieFinder, - @Value("#{ systemProperties['user.region'] }") defaultLocale: String) { - this.movieFinder = movieFinder - this.defaultLocale = defaultLocale - } - - // ... - } ----- -====== - -[tabs] -====== -Java:: -+ -[source,java,indent=0,subs="verbatim,quotes",role="primary"] ----- - public class MovieRecommender { - - private String defaultLocale; - - private CustomerPreferenceDao customerPreferenceDao; - - public MovieRecommender(CustomerPreferenceDao customerPreferenceDao, - @Value("#{systemProperties['user.country']}") String defaultLocale) { - this.customerPreferenceDao = customerPreferenceDao; - this.defaultLocale = defaultLocale; - } - - // ... - } ----- - -Kotlin:: -+ -[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] ----- - class MovieRecommender(private val customerPreferenceDao: CustomerPreferenceDao, - @Value("#{systemProperties['user.country']}") private val defaultLocale: String) { - // ... - } ----- -====== - +include-code::./SimpleMovieLister[tag=snippet,indent=0] +include-code::./MovieRecommender[tag=snippet,indent=0] +You can also refer to other bean properties by name, as the following example shows: +include-code::./ShapeGuess[tag=snippet,indent=0] diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/CustomerPreferenceDao.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/CustomerPreferenceDao.java new file mode 100644 index 0000000000..cadf841666 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/CustomerPreferenceDao.java @@ -0,0 +1,20 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +public class CustomerPreferenceDao { +} diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.java new file mode 100644 index 0000000000..6c795eb475 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.java @@ -0,0 +1,35 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +import org.springframework.beans.factory.annotation.Value; + +// tag::snippet[] +public class FieldValueTestBean { + + @Value("#{ systemProperties['user.region'] }") + private String defaultLocale; + + public void setDefaultLocale(String defaultLocale) { + this.defaultLocale = defaultLocale; + } + + public String getDefaultLocale() { + return this.defaultLocale; + } +} +// end::snippet[] diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieFinder.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieFinder.java new file mode 100644 index 0000000000..aee9cba8d7 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieFinder.java @@ -0,0 +1,20 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +public class MovieFinder { +} diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.java new file mode 100644 index 0000000000..8ac7b7d9f3 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.java @@ -0,0 +1,36 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +import org.springframework.beans.factory.annotation.Value; + +// tag::snippet[] +public class MovieRecommender { + + private String defaultLocale; + + private CustomerPreferenceDao customerPreferenceDao; + + public MovieRecommender(CustomerPreferenceDao customerPreferenceDao, + @Value("#{systemProperties['user.country']}") String defaultLocale) { + this.customerPreferenceDao = customerPreferenceDao; + this.defaultLocale = defaultLocale; + } + + // ... +} +// end::snippet[] diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.java new file mode 100644 index 0000000000..957bb3a5d2 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.java @@ -0,0 +1,36 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +import org.springframework.beans.factory.annotation.Value; + +// tag::snippet[] +public class NumberGuess { + + private double randomNumber; + + @Value("#{ T(java.lang.Math).random() * 100.0 }") + public void setRandomNumber(double randomNumber) { + this.randomNumber = randomNumber; + } + + public double getRandomNumber() { + return randomNumber; + } +} +// end::snippet[] + diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.java new file mode 100644 index 0000000000..aae1ced322 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.java @@ -0,0 +1,35 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +import org.springframework.beans.factory.annotation.Value; + +// tag::snippet[] +public class PropertyValueTestBean { + + private String defaultLocale; + + @Value("#{ systemProperties['user.region'] }") + public void setDefaultLocale(String defaultLocale) { + this.defaultLocale = defaultLocale; + } + + public String getDefaultLocale() { + return this.defaultLocale; + } +} +// end::snippet[] \ No newline at end of file diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.java new file mode 100644 index 0000000000..0fb0da1322 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.java @@ -0,0 +1,35 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +import org.springframework.beans.factory.annotation.Value; + +// tag::snippet[] +public class ShapeGuess { + + private double initialShapeSeed; + + @Value("#{ numberGuess.randomNumber }") + public void setInitialShapeSeed(double initialShapeSeed) { + this.initialShapeSeed = initialShapeSeed; + } + + public double getInitialShapeSeed() { + return initialShapeSeed; + } +} +// end::snippet[] diff --git a/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.java b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.java new file mode 100644 index 0000000000..8298ace056 --- /dev/null +++ b/framework-docs/src/main/java/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.java @@ -0,0 +1,37 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; + +// tag::snippet[] +public class SimpleMovieLister { + + private MovieFinder movieFinder; + private String defaultLocale; + + @Autowired + public void configure(MovieFinder movieFinder, + @Value("#{ systemProperties['user.region'] }") String defaultLocale) { + this.movieFinder = movieFinder; + this.defaultLocale = defaultLocale; + } + + // ... +} +// end::snippet[] \ No newline at end of file diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.kt b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.kt new file mode 100644 index 0000000000..af31d843a5 --- /dev/null +++ b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/FieldValueTestBean.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef + +import org.springframework.beans.factory.annotation.Value + +// tag::snippet[] +class FieldValueTestBean { + + @field:Value("#{ systemProperties['user.region'] }") + lateinit var defaultLocale: String +} +// end::snippet[] \ No newline at end of file diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.kt b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.kt new file mode 100644 index 0000000000..6dd298a7bc --- /dev/null +++ b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef + +import org.springframework.beans.factory.annotation.Value + +// tag::snippet[] +class MovieRecommender(private val customerPreferenceDao: CustomerPreferenceDao, + @Value("#{systemProperties['user.country']}") + private val defaultLocale: String) { + // ... +} +// end::snippet[] diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.kt b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.kt new file mode 100644 index 0000000000..50083a83f8 --- /dev/null +++ b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/NumberGuess.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef + +import org.springframework.beans.factory.annotation.Value + +// tag::snippet[] +class NumberGuess { + + @set:Value("#{ T(java.lang.Math).random() * 100.0 }") + var randomNumber: Double = 0.0 +} +// end::snippet[] \ No newline at end of file diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.kt b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.kt new file mode 100644 index 0000000000..42c2808a38 --- /dev/null +++ b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef + +import org.springframework.beans.factory.annotation.Value + +// tag::snippet[] +class PropertyValueTestBean { + + @set:Value("#{ systemProperties['user.region'] }") + lateinit var defaultLocale: String +} +// end::snippet[] \ No newline at end of file diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.kt b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.kt new file mode 100644 index 0000000000..ee713a26d5 --- /dev/null +++ b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef + +import org.springframework.beans.factory.annotation.Value + +// tag::snippet[] +class ShapeGuess { + + @set:Value("#{ numberGuess.randomNumber }") + var initialShapeSeed: Double = 0.0 +} +// end::snippet[] diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.kt b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.kt new file mode 100644 index 0000000000..a3891db543 --- /dev/null +++ b/framework-docs/src/main/kotlin/org/springframework/docs/core/expressions/expressionsbeandef/SimpleMovieLister.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.docs.core.expressions.expressionsbeandef + +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value + +// tag::snippet[] +class SimpleMovieLister { + + private lateinit var movieFinder: MovieFinder + private lateinit var defaultLocale: String + + @Autowired + fun configure(movieFinder: MovieFinder, + @Value("#{ systemProperties['user.region'] }") defaultLocale: String) { + this.movieFinder = movieFinder + this.defaultLocale = defaultLocale + } + + // ... +} +// end::snippet[] \ No newline at end of file diff --git a/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.xml b/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.xml new file mode 100644 index 0000000000..7092424296 --- /dev/null +++ b/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/MovieRecommender.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.xml b/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.xml new file mode 100644 index 0000000000..d1bdade08d --- /dev/null +++ b/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/PropertyValueTestBean.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.xml b/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.xml new file mode 100644 index 0000000000..c7703c38ea --- /dev/null +++ b/framework-docs/src/main/resources/org/springframework/docs/core/expressions/expressionsbeandef/ShapeGuess.xml @@ -0,0 +1,13 @@ + + + + + + + + +