Fix syntax errors in code examples in reference manual

This commit fixes syntax errors in Java, Kotlin, and XML examples in
the reference manual, such as Java syntax in Kotlin examples,
unbalanced braces and parentheses, and unclosed XML elements.

Closes gh-37392
This commit is contained in:
Sam Brannen
2026-10-04 15:27:56 +02:00
parent f96403da2a
commit 14dc767dd6
18 changed files with 40 additions and 38 deletions
@@ -946,11 +946,11 @@ Kotlin::
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
// create a startup step and start recording
try (val scanPackages = getApplicationStartup().start("spring.context.base-packages.scan")) {
// add tagging information to the current step
scanPackages.tag("packages", () -> Arrays.toString(basePackages));
// perform the actual phase we're instrumenting
this.scanner.scan(basePackages);
getApplicationStartup().start("spring.context.base-packages.scan").use { scanPackages ->
// add tagging information to the current step
scanPackages.tag("packages") { Arrays.toString(basePackages) }
// perform the actual phase we're instrumenting
this.scanner.scan(basePackages)
}
----
======
@@ -295,7 +295,7 @@ The following example demonstrates collection merging:
</props>
</property>
</bean>
<beans>
</beans>
----
Notice the use of the `merge=true` attribute on the `<props/>` element of the
@@ -134,7 +134,7 @@ Java::
protected Command createCommand() {
return asyncCommand();
}
}
};
}
----
@@ -452,7 +452,7 @@ Kotlin::
val expression = "members?.^[nationality == 'Serbian']?.name" // <1>
// evaluates to "Nikola Tesla"
String name = parser.parseExpression(expression)
var name = parser.parseExpression(expression)
.getValue(context, String::class.java)
society.members = null
@@ -521,7 +521,7 @@ latter being used to access a file in the filesystem):
[source,xml,indent=0,subs="verbatim,quotes"]
----
<property name="template" value="classpath:some/resource/path/myTemplate.txt">
<property name="template" value="classpath:some/resource/path/myTemplate.txt"/>
----
[source,xml,indent=0,subs="verbatim,quotes"]
@@ -597,7 +597,7 @@ Kotlin::
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
@Component
class MyBean(@Value("\${templates.path}") private val templates: Resource[])
class MyBean(@Value("\${templates.path}") private val templates: Array<Resource>)
----
======
@@ -250,7 +250,7 @@ Java::
public class MyConstraintValidator implements ConstraintValidator {
@Autowired;
@Autowired
private Foo aDependency;
// ...
@@ -556,7 +556,7 @@ Java::
public TitlesAfterDateStoredProcedure(DataSource dataSource) {
super(dataSource, SPROC_NAME);
declareParameter(new SqlParameter(CUTOFF_DATE_PARAM, Types.DATE);
declareParameter(new SqlParameter(CUTOFF_DATE_PARAM, Types.DATE));
declareParameter(new SqlOutParameter("titles", OracleTypes.CURSOR, new TitleMapper()));
compile();
}
@@ -360,7 +360,7 @@ Or you may pass in a parameter object with bean properties or record components:
----
// assuming id, name, age properties on Person
db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
.bindProperties(new Person("joe", "Joe", 34);
.bindProperties(new Person("joe", "Joe", 34));
----
Alternatively, you can use positional parameters for binding values to statements.
@@ -301,7 +301,6 @@ Java::
public Mono<Object> doInTransaction(ReactiveTransaction status) {
return updateOperation1().then(updateOperation2)
.doOnError(SomeBusinessException.class, e -> status.setRollbackOnly());
}
}
});
----
@@ -310,11 +309,11 @@ Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
transactionalOperator.execute(object : TransactionCallback() {
transactionalOperator.execute(object : TransactionCallback<Any> {
override fun doInTransactionWithoutResult(status: ReactiveTransaction) {
updateOperation1().then(updateOperation2)
.doOnError(SomeBusinessException.class, e -> status.setRollbackOnly())
override fun doInTransaction(status: ReactiveTransaction): Mono<Any> {
return updateOperation1().then(updateOperation2)
.doOnError(SomeBusinessException::class.java) { status.setRollbackOnly() }
}
})
----
@@ -192,7 +192,7 @@ Kotlin::
----
val requester = RSocketRequester.builder().tcp("localhost", 7000)
URI url = URI.create("https://example.org:8080/rsocket");
val url = URI.create("https://example.org:8080/rsocket")
val requester = RSocketRequester.builder().webSocket(url)
----
======
@@ -304,7 +304,7 @@ Kotlin::
.build()
val responder =
RSocketMessageHandler.responder(strategies, new ClientHandler()); // <2>
RSocketMessageHandler.responder(strategies, ClientHandler()) // <2>
val requester = RSocketRequester.builder()
.rsocketConnector { it.acceptor(responder) } // <3>
@@ -503,7 +503,7 @@ Java::
+
[source,java,indent=0,subs="verbatim,quotes"]
----
Mono<AirportLocation> location = requester.route("find.radar.EWR"))
Mono<AirportLocation> location = requester.route("find.radar.EWR")
.retrieveMono(AirportLocation.class);
----
@@ -182,7 +182,7 @@ Kotlin::
@Bean
fun apiPropertiesRegistrar(apiServer: ApiServer): DynamicPropertyRegistrar {
return registry -> registry.add("api.url", apiServer::getUrl)
return DynamicPropertyRegistrar { registry -> registry.add("api.url", apiServer::url) }
}
}
----
@@ -583,7 +583,7 @@ Kotlin::
@Transactional
@Test(expected = ...)
void updateWithEntityManagerFlush() {
fun updateWithEntityManagerFlush() {
updateEntityInJpaPersistenceContext()
// Manual flush is required to avoid false positive in test
entityManager.flush()
@@ -158,16 +158,16 @@ Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
@ExtendWith(SpringExtension.class)
@ExtendWith(SpringExtension::class)
@WebAppConfiguration("classpath:META-INF/web-resources") // <1>
@ContextHierarchy({
@ContextConfiguration(classes = RootConfig.class),
@ContextConfiguration(classes = WebConfig.class)
})
@ContextHierarchy(
ContextConfiguration(classes = [RootConfig::class]),
ContextConfiguration(classes = [WebConfig::class])
)
class MyTests {
@Autowired
lateinit var wac: WebApplicationContext; // <2>
lateinit var wac: WebApplicationContext // <2>
lateinit var client: WebTestClient
@@ -394,8 +394,6 @@ Java::
+
[source,java,indent=0,subs="verbatim,quotes"]
----
import org.springframework.test.web.reactive.server.expectBody
client.get().uri("/persons/1")
.exchange()
.expectStatus().isOk()
@@ -409,6 +407,8 @@ Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
import org.springframework.test.web.reactive.server.expectBody
client.get().uri("/persons/1")
.exchange()
.expectStatus().isOk()
@@ -22,8 +22,6 @@ Java::
.attribute("myAttribute", "...")
.retrieve()
.bodyToMono(Void.class);
}
----
Kotlin::
@@ -60,9 +60,8 @@ Java::
if (errors.hasErrors()) {
// ...
}
status.setComplete();
// ...
}
status.setComplete();
// ...
}
}
----
@@ -87,6 +87,8 @@ Java::
@Override
public void modelAttribute(@Nullable ModelAttribute modelAttribute, ParameterErrors errors) {
// ...
}
// ...
@@ -329,8 +329,10 @@ Kotlin::
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
fun sse(): RouterFunction<ServerResponse> = router {
GET("/sse") { request -> ServerResponse.sse { sseBuilder ->
// Save the sseBuilder object somewhere..
GET("/sse") { request ->
ServerResponse.sse { sseBuilder ->
// Save the sseBuilder object somewhere..
}
}
}
@@ -87,6 +87,8 @@ Java::
@Override
public void modelAttribute(@Nullable ModelAttribute modelAttribute, ParameterErrors errors) {
// ...
}
// ...