Add auto-configuration for JdbcClient
Closes gh-36579
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[[data.sql]]
|
||||
== SQL Databases
|
||||
The {spring-framework}[Spring Framework] provides extensive support for working with SQL databases, from direct JDBC access using `JdbcTemplate` to complete "`object relational mapping`" technologies such as Hibernate.
|
||||
The {spring-framework}[Spring Framework] provides extensive support for working with SQL databases, from direct JDBC access using `JdbcClient` or `JdbcTemplate` to complete "`object relational mapping`" technologies such as Hibernate.
|
||||
{spring-data}[Spring Data] provides an additional level of functionality: creating `Repository` implementations directly from interfaces and using conventions to generate queries from your method names.
|
||||
|
||||
|
||||
@@ -176,6 +176,17 @@ If more than one `JdbcTemplate` is defined and no primary candidate exists, the
|
||||
|
||||
|
||||
|
||||
[[data.sql.jdbc-client]]
|
||||
=== Using JdbcClient
|
||||
Spring's `JdbcClient` is auto-configured based on the presence of a `NamedParameterJdbcTemplate`.
|
||||
You can inject it directly in your own beans as well, as shown in the following example:
|
||||
|
||||
include::code:MyBean[]
|
||||
|
||||
If you rely on auto-configuration to create the underlying `JdbcTemplate`, any customization using `spring.jdbc.template.*` properties are taken into account in the client as well.
|
||||
|
||||
|
||||
|
||||
[[data.sql.jpa-and-spring-data]]
|
||||
=== JPA and Spring Data JPA
|
||||
The Java Persistence API is a standard technology that lets you "`map`" objects to relational databases.
|
||||
|
||||
@@ -217,6 +217,7 @@ Spring Boot will automatically detect beans of the following types that depends
|
||||
- `AbstractEntityManagerFactoryBean` (unless configprop:spring.jpa.defer-datasource-initialization[] is set to `true`)
|
||||
- `DSLContext` (jOOQ)
|
||||
- `EntityManagerFactory` (unless configprop:spring.jpa.defer-datasource-initialization[] is set to `true`)
|
||||
- `JdbcClient`
|
||||
- `JdbcOperations`
|
||||
- `NamedParameterJdbcOperations`
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2012-2023 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.boot.docs.data.sql.jdbcclient;
|
||||
|
||||
import org.springframework.jdbc.core.simple.JdbcClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private final JdbcClient jdbcClient;
|
||||
|
||||
public MyBean(JdbcClient jdbcClient) {
|
||||
this.jdbcClient = jdbcClient;
|
||||
}
|
||||
|
||||
public void doSomething() {
|
||||
/* @chomp:line this.jdbcClient ... */ this.jdbcClient.sql("delete from customer").update();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user