@ -2893,16 +2893,9 @@ Jersey has some native Spring support, so we also provide auto-configuration sup
To get started with Jersey, include the `spring-boot-starter-jersey` as a dependency and then you need one `@Bean` of type `ResourceConfig` in which you register all the endpoints, as shown in the following example:
[source,java,pending-extract=true, indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@Component
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(Endpoint.class);
}
}
include::{include-springbootfeatures}/webapplications/jersey/JerseyConfig.java[]
----
WARNING: Jersey's support for scanning executable archives is rather limited.
@ -2913,18 +2906,9 @@ For more advanced customizations, you can also register an arbitrary number of b
All the registered endpoints should be `@Components` with HTTP resource annotations (`@GET` and others), as shown in the following example:
[source,java,pending-extract=true, indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@Component
@Path("/hello")
public class Endpoint {
@GET
public String message() {
return "Hello";
}
}
include::{include-springbootfeatures}/webapplications/jersey/Endpoint.java[]
----
Since the `Endpoint` is a Spring `@Component`, its lifecycle is managed by Spring and you can use the `@Autowired` annotation to inject dependencies and use the `@Value` annotation to inject external configuration.
@ -3036,21 +3020,9 @@ If you need to programmatically configure your embedded servlet container, you c
`WebServerFactoryCustomizer` provides access to the `ConfigurableServletWebServerFactory`, which includes numerous customization setter methods.
The following example shows programmatically setting the port:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;
@Component
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory server) {
server.setPort(9000);
}
}
include::{include-springbootfeatures}/webapplications/embeddedservletcontainer/CustomizationBean.java[]
----
`TomcatServletWebServerFactory`, `JettyServletWebServerFactory` and `UndertowServletWebServerFactory` are dedicated variants of `ConfigurableServletWebServerFactory` that have additional customization setter methods for Tomcat, Jetty and Undertow respectively.
@ -3058,7 +3030,7 @@ The following example shows how to customize `TomcatServletWebServerFactory` tha
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-springbootfeatures}/webapplications/TomcatServerCustomizer.java[]
include::{include-springbootfeatures}/webapplications/embeddedservletcontainer/ TomcatServerCustomizer.java[]
----
@ -3226,24 +3198,9 @@ This is done on purpose since this builder is stateful and you shouldn't create
The following code shows a typical example:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
@Service
public class MyService {
private final Mono<RSocketRequester> rsocketRequester;
public MyService(RSocketRequester.Builder rsocketRequesterBuilder) {
this.rsocketRequester = rsocketRequesterBuilder
.connectTcp("example.org", 9898).cache();
}
public Mono<User> someRSocketCall(String name) {
return this.rsocketRequester.flatMap(req ->
req.route("user").data(name).retrieveMono(User.class));
}
}
include::{include-springbootfeatures}/rsocket/MyService.java[]
----
@ -3310,7 +3267,7 @@ Spring Boot provides convenience methods that can be used to override access rul
For example, you can customize your security configuration by adding something like:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
include::{include-springbootfeatures}/security/CustomWebFluxSecurityConfiguration.java[]
----
@ -3389,19 +3346,9 @@ By default, Spring Security's `OAuth2LoginAuthenticationFilter` only processes U
If you want to customize the `redirect-uri` to use a different pattern, you need to provide configuration to process that custom pattern.
For example, for servlet applications, you can add your own `SecurityFilterChain` that resembles the following:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
.redirectionEndpoint()
.baseUri("/custom-callback");
return http.build();
}
include::{include-springbootfeatures}/security/OAuthClientConfiguration.java[]
----
TIP: Spring Boot auto-configures an `InMemoryOAuth2AuthorizedClientService` which is used by Spring Security for the management of client registrations.
@ -3713,25 +3660,9 @@ For example, the following section in `application.properties` shows how you can
=== Using JdbcTemplate
Spring's `JdbcTemplate` and `NamedParameterJdbcTemplate` classes are auto-configured, and you can `@Autowire` them directly into your own beans, as shown in the following example:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
@Component
public class MyBean {
private final JdbcTemplate jdbcTemplate;
@Autowired
public MyBean(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
// ...
}
include::{include-springbootfeatures}/sql/jdbctemplate/MyBean.java[]
----
You can customize some properties of the template by using the `spring.jdbc.template.*` properties, as shown in the following example:
@ -3773,49 +3704,9 @@ By default, all packages below your main configuration class (the one annotated
Any classes annotated with `@Entity`, `@Embeddable`, or `@MappedSuperclass` are considered.
A typical entity class resembles the following example:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
package com.example.myapp.domain;
import java.io.Serializable;
import javax.persistence.*;
@Entity
public class City implements Serializable {
@Id
@GeneratedValue
private Long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String state;
// ... additional members, often include @OneToMany mappings
protected City() {
// no-args constructor required by JPA spec
// this one is protected since it shouldn't be used directly
}
public City(String name, String state) {
this.name = name;
this.state = state;
}
public String getName() {
return this.name;
}
public String getState() {
return this.state;
}
// ... etc
}
include::{include-springbootfeatures}/sql/jpa/City.java[]
----
TIP: You can customize entity scanning locations by using the `@EntityScan` annotation.
@ -3836,20 +3727,9 @@ If you use auto-configuration, repositories are searched from the package contai
The following example shows a typical Spring Data repository interface definition:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
package com.example.myapp.domain;
import org.springframework.data.domain.*;
import org.springframework.data.repository.*;
public interface CityRepository extends Repository<City, Long> {
Page<City> findAll(Pageable pageable);
City findByNameAndStateAllIgnoringCase(String name, String state);
}
include::{include-springbootfeatures}/sql/jpa/CityRepository.java[]
----
Spring Data JPA repositories support three different modes of bootstrapping: default, deferred, and lazy.
@ -3979,34 +3859,20 @@ The following listing shows an example:
==== Using DSLContext
The fluent API offered by jOOQ is initiated through the `org.jooq.DSLContext` interface.
Spring Boot auto-configures a `DSLContext` as a Spring Bean and connects it to your application `DataSource`.
To use the `DSLContext`, you can `@Autowire` it, as shown in the following example:
To use the `DSLContext`, you can inject it, as shown in the following example:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
@Component
public class JooqExample implements CommandLineRunner {
private final DSLContext create;
@Autowired
public JooqExample(DSLContext dslContext) {
this.create = dslContext;
}
}
include::{include-springbootfeatures}/sql/jooq/JooqExample.java[tag=!method]
----
TIP: The jOOQ manual tends to use a variable named `create` to hold the `DSLContext`.
You can then use the `DSLContext` to construct your queries, as shown in the following example:
[source,java,pending-extract=true, indent=0]
[source,java,indent=0]
----
public List<GregorianCalendar> authorsBornAfter1980() {
return this.create.selectFrom(AUTHOR)
.where(AUTHOR.DATE_OF_BIRTH.greaterThan(new GregorianCalendar(1980, 0, 1)))
.fetch(AUTHOR.DATE_OF_BIRTH);
}
include::{include-springbootfeatures}/sql/jooq/JooqExample.java[tag=method]
----