JAVA-31190: Preparation for migrating spring-boot-modules to version 3. (#15834)

This commit is contained in:
Harry9656 2024-02-27 02:49:02 +01:00 committed by GitHub
parent 74da22b9c4
commit aefd833c3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
190 changed files with 1052 additions and 832 deletions

View File

@ -11,16 +11,16 @@
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath> <relativePath>../parent-boot-3</relativePath>
</parent> </parent>
<modules> <modules>
<module>spring-boot-admin</module> <module>spring-boot-admin</module>
<module>spring-boot-angular</module> <module>spring-boot-angular</module>
<module>spring-boot-annotations</module> <module>spring-boot-annotations</module>
<module>spring-boot-annotations-2</module> <!-- <module>spring-boot-annotations-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-artifacts</module> <module>spring-boot-artifacts</module>
<module>spring-boot-artifacts-2</module> <module>spring-boot-artifacts-2</module>
<module>spring-boot-autoconfiguration</module> <module>spring-boot-autoconfiguration</module>
@ -31,33 +31,33 @@
<module>spring-boot-config-jpa-error</module> <module>spring-boot-config-jpa-error</module>
<module>spring-boot-ctx-fluent</module> <module>spring-boot-ctx-fluent</module>
<module>spring-boot-deployment</module> <module>spring-boot-deployment</module>
<module>spring-boot-di</module> <!-- <module>spring-boot-di</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-disable-logging</module> <module>spring-boot-disable-logging</module>
<module>spring-boot-ci-cd</module> <module>spring-boot-ci-cd</module>
<!-- <module>spring-boot-cli</module> --> <!-- Not a maven project --> <!-- <module>spring-boot-cli</module> --> <!-- Not a maven project -->
<module>spring-boot-custom-starter</module> <!-- <module>spring-boot-custom-starter</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-crud</module> <module>spring-boot-crud</module>
<module>spring-boot-data</module> <module>spring-boot-data</module>
<module>spring-boot-environment</module> <module>spring-boot-environment</module>
<module>spring-boot-exceptions</module> <module>spring-boot-exceptions</module>
<module>spring-boot-flowable</module> <module>spring-boot-flowable</module>
<module>spring-boot-graphql</module> <!-- <module>spring-boot-graphql</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!--<module>spring-boot-groovy</module>--> <!-- failing after upgrading to jdk17--> <!--<module>spring-boot-groovy</module>--> <!-- failing after upgrading to jdk17-->
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project --> <!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
<module>spring-boot-jasypt</module> <module>spring-boot-jasypt</module>
<module>spring-boot-jsp</module> <!-- <module>spring-boot-jsp</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-keycloak</module> <module>spring-boot-keycloak</module>
<module>spring-boot-keycloak-2</module> <module>spring-boot-keycloak-2</module>
<module>spring-boot-libraries</module> <!-- <module>spring-boot-libraries</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-libraries-2</module> <!-- <module>spring-boot-libraries-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-process-automation</module> <module>spring-boot-process-automation</module>
<module>spring-boot-logging-logback</module> <module>spring-boot-logging-logback</module>
<module>spring-boot-logging-log4j2</module> <module>spring-boot-logging-log4j2</module>
<module>spring-boot-mvc</module> <!-- <module>spring-boot-mvc</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-mvc-2</module> <module>spring-boot-mvc-2</module>
<module>spring-boot-mvc-3</module> <module>spring-boot-mvc-3</module>
<module>spring-boot-mvc-4</module> <module>spring-boot-mvc-4</module>
<module>spring-boot-mvc-5</module> <!-- <module>spring-boot-mvc-5</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-mvc-birt</module> <module>spring-boot-mvc-birt</module>
<module>spring-boot-mvc-jersey</module> <module>spring-boot-mvc-jersey</module>
<module>spring-boot-nashorn</module> <module>spring-boot-nashorn</module>
@ -65,34 +65,34 @@
<module>spring-boot-performance</module> <module>spring-boot-performance</module>
<module>spring-boot-property-exp</module> <module>spring-boot-property-exp</module>
<module>spring-boot-request-params</module> <module>spring-boot-request-params</module>
<module>spring-boot-runtime</module> <!-- <module>spring-boot-runtime</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-runtime-2</module> <!-- <module>spring-boot-runtime-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-security</module> <module>spring-boot-security</module>
<module>spring-boot-security-2</module> <module>spring-boot-security-2</module>
<module>spring-boot-ssl-bundles</module> <module>spring-boot-ssl-bundles</module>
<module>spring-boot-telegram</module> <module>spring-boot-telegram</module>
<module>spring-boot-springdoc</module> <!-- <module>spring-boot-springdoc</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-swagger</module> <!-- <module>spring-boot-swagger</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-swagger-2</module> <!-- <module>spring-boot-swagger-2</module>--> <!-- failing after upgrading to spring boot 3. Swagger codegen yet not compatible?!-->
<module>spring-boot-swagger-jwt</module> <module>spring-boot-swagger-jwt</module>
<module>spring-boot-swagger-keycloak</module> <module>spring-boot-swagger-keycloak</module>
<module>spring-boot-swagger-springfox</module> <module>spring-boot-swagger-springfox</module>
<module>spring-boot-testing</module> <!-- <module>spring-boot-testing</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-testing-2</module> <!-- <module>spring-boot-testing-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-testing-spock</module> <module>spring-boot-testing-spock</module>
<module>spring-boot-vue</module> <module>spring-boot-vue</module>
<module>spring-boot-actuator</module> <module>spring-boot-actuator</module>
<module>spring-boot-data-2</module> <module>spring-boot-data-2</module>
<module>spring-boot-validation</module> <module>spring-boot-validation</module>
<module>spring-boot-data-3</module> <module>spring-boot-data-3</module>
<module>spring-caching</module> <!-- <module>spring-caching</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-caching-2</module> <!-- <module>spring-caching-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-redis</module> <!-- <module>spring-boot-redis</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-cassandre</module> <module>spring-boot-cassandre</module>
<module>spring-boot-react</module> <!-- <module>spring-boot-react</module>--> <!-- failing after upgrading to spring boot 3.2.x. very old node version which is not available now. -->
<!-- <module>spring-boot-3</module> --> <!-- JAVA-20931 --> <!-- <module>spring-boot-3</module> --> <!-- JAVA-20931 -->
<module>spring-boot-3-grpc</module> <module>spring-boot-3-grpc</module>
<module>spring-boot-3-native</module> <!-- <module>spring-boot-3-native</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-3-observation</module> <module>spring-boot-3-observation</module>
<module>spring-boot-3-test-pitfalls</module> <module>spring-boot-3-test-pitfalls</module>
<module>spring-boot-3-testcontainers</module> <module>spring-boot-3-testcontainers</module>
@ -100,10 +100,10 @@
<module>spring-boot-resilience4j</module> <module>spring-boot-resilience4j</module>
<module>spring-boot-properties</module> <module>spring-boot-properties</module>
<module>spring-boot-properties-2</module> <module>spring-boot-properties-2</module>
<module>spring-boot-properties-3</module> <!-- <module>spring-boot-properties-3</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-properties-4</module> <module>spring-boot-properties-4</module>
<module>spring-boot-properties-migrator-demo</module> <module>spring-boot-properties-migrator-demo</module>
<module>spring-boot-aws</module> <module>spring-boot-aws</module> <!-- This project is Spring Boot 2 and cannot be updated -->
<module>spring-boot-keycloak-adapters</module> <module>spring-boot-keycloak-adapters</module>
<module>spring-boot-mvc-legacy</module> <module>spring-boot-mvc-legacy</module>
<module>spring-boot-springdoc-2</module> <module>spring-boot-springdoc-2</module>

View File

@ -8,10 +8,9 @@
<name>helloworld-grpc-consumer</name> <name>helloworld-grpc-consumer</name>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-3-grpc</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -28,7 +27,6 @@
</dependencies> </dependencies>
<properties> <properties>
<spring-boot.version>3.2.0</spring-boot.version>
<grpc-spring-boot-starter.version>2.15.0.RELEASE</grpc-spring-boot-starter.version> <grpc-spring-boot-starter.version>2.15.0.RELEASE</grpc-spring-boot-starter.version>
</properties> </properties>

View File

@ -84,6 +84,7 @@
<os-maven-plugin.version>1.7.1</os-maven-plugin.version> <os-maven-plugin.version>1.7.1</os-maven-plugin.version>
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version> <protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
<annotation-api.version>1.3.2</annotation-api.version> <annotation-api.version>1.3.2</annotation-api.version>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties> </properties>
</project> </project>

View File

@ -8,10 +8,9 @@
<name>helloworld-grpc-provider</name> <name>helloworld-grpc-provider</name>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-3-grpc</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -28,7 +27,6 @@
</dependencies> </dependencies>
<properties> <properties>
<spring-boot.version>3.2.0</spring-boot.version>
<grpc-spring-boot-starter.version>2.15.0.RELEASE</grpc-spring-boot-starter.version> <grpc-spring-boot-starter.version>2.15.0.RELEASE</grpc-spring-boot-starter.version>
</properties> </properties>

View File

@ -3,17 +3,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-3-grpc</artifactId> <artifactId>spring-boot-3-grpc</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<name>spring-boot-3-grpc</name> <name>spring-boot-3-grpc</name>
<packaging>pom</packaging> <packaging>pom</packaging>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-modules</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modules> <modules>

View File

@ -9,10 +9,9 @@
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -100,6 +99,7 @@
<springdoc.version>2.0.0</springdoc.version> <springdoc.version>2.0.0</springdoc.version>
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version> <maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<native.maven.plugin.version>0.9.17</native.maven.plugin.version> <native.maven.plugin.version>0.9.17</native.maven.plugin.version>
<java.version>17</java.version>
</properties> </properties>
</project> </project>

View File

@ -8,10 +8,9 @@
<description>Demo project for Spring Boot 3 Observation</description> <description>Demo project for Spring Boot 3 Observation</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -109,6 +108,7 @@
<properties> <properties>
<start-class>com.baeldung.samples.SimpleObservationApplication</start-class> <start-class>com.baeldung.samples.SimpleObservationApplication</start-class>
<p6spy-spring-boot-starter.version>1.9.0</p6spy-spring-boot-starter.version> <p6spy-spring-boot-starter.version>1.9.0</p6spy-spring-boot-starter.version>
<java.version>17</java.version>
</properties> </properties>
</project> </project>

View File

@ -9,10 +9,9 @@
<description>Demo project for Spring Boot Testing Pitfalls</description> <description>Demo project for Spring Boot Testing Pitfalls</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -82,6 +81,7 @@
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version> <org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version> <lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version> <maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<java.version>17</java.version>
</properties> </properties>
</project> </project>

View File

@ -9,10 +9,9 @@
<description>Testcontainer Improvements in Spring Boot 3</description> <description>Testcontainer Improvements in Spring Boot 3</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -96,6 +95,7 @@
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version> <maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<testcontainers.version>1.18.3</testcontainers.version> <testcontainers.version>1.18.3</testcontainers.version>
<rest-assured.version>5.3.1</rest-assured.version> <rest-assured.version>5.3.1</rest-assured.version>
<java.version>17</java.version>
</properties> </properties>
</project> </project>

View File

@ -9,10 +9,9 @@
<description>URL Matching in Spring Boot 3</description> <description>URL Matching in Spring Boot 3</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -46,7 +45,6 @@
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<version>${spring-test.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -94,7 +92,6 @@
</build> </build>
<properties> <properties>
<spring-test.version>6.0.6</spring-test.version>
<javax.servlet-api.version>3.1.0</javax.servlet-api.version> <javax.servlet-api.version>3.1.0</javax.servlet-api.version>
<reactor-core.version>3.6.0</reactor-core.version> <reactor-core.version>3.6.0</reactor-core.version>
<reactor-test.version>3.6.0></reactor-test.version> <reactor-test.version>3.6.0></reactor-test.version>

View File

@ -9,10 +9,9 @@
<description>This is simple boot application for Spring boot actuator test</description> <description>This is simple boot application for Spring boot actuator test</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -25,13 +25,13 @@
<dependency> <dependency>
<groupId>de.codecentric</groupId> <groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId> <artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring-boot-admin-server.version}</version> <version>${spring-boot.version}</version>
</dependency> </dependency>
<!--Add login page and logout feature --> <!--Add login page and logout feature -->
<dependency> <dependency>
<groupId>de.codecentric</groupId> <groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui-login</artifactId> <artifactId>spring-boot-admin-server-ui</artifactId>
<version>${spring-boot-admin-server-ui-login.version}</version> <version>${spring-boot.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -45,7 +45,7 @@
<dependency> <dependency>
<groupId>de.codecentric</groupId> <groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId> <artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin-starter-client.version}</version> <version>${spring-boot.version}</version>
</dependency> </dependency>
<!--mail notifications --> <!--mail notifications -->
<dependency> <dependency>
@ -69,16 +69,8 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-maven-plugin.version}</version>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<properties>
<spring-boot-admin-server.version>2.4.1</spring-boot-admin-server.version>
<spring-boot-admin-starter-client.version>2.4.1</spring-boot-admin-starter-client.version>
<spring-boot-admin-server-ui-login.version>1.5.7</spring-boot-admin-server-ui-login.version>
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
</properties>
</project> </project>

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@ -17,6 +18,7 @@ import de.codecentric.boot.admin.server.config.AdminServerProperties;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
public class WebSecurityConfig { public class WebSecurityConfig {
private final AdminServerProperties adminServer; private final AdminServerProperties adminServer;
public WebSecurityConfig(AdminServerProperties adminServer) { public WebSecurityConfig(AdminServerProperties adminServer) {
@ -29,32 +31,24 @@ public class WebSecurityConfig {
successHandler.setTargetUrlParameter("redirectTo"); successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(this.adminServer.getContextPath() + "/"); successHandler.setDefaultTargetUrl(this.adminServer.getContextPath() + "/");
http.authorizeRequests() http.authorizeHttpRequests(req -> req.requestMatchers(this.adminServer.getContextPath() + "/assets/**")
.antMatchers(this.adminServer.getContextPath() + "/assets/**") .permitAll()
.permitAll() .requestMatchers(this.adminServer.getContextPath() + "/login")
.antMatchers(this.adminServer.getContextPath() + "/login") .permitAll()
.permitAll() .anyRequest()
.anyRequest() .authenticated())
.authenticated() .formLogin(formLogin -> formLogin.loginPage(this.adminServer.getContextPath() + "/login")
.and() .successHandler(successHandler))
.formLogin() .logout((logout) -> logout.logoutUrl(this.adminServer.getContextPath() + "/logout"))
.loginPage(this.adminServer.getContextPath() + "/login") .httpBasic(Customizer.withDefaults())
.successHandler(successHandler) .csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and() .ignoringRequestMatchers(
.logout() new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances", HttpMethod.POST.toString()),
.logoutUrl(this.adminServer.getContextPath() + "/logout") new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances/*", HttpMethod.DELETE.toString()),
.and() new AntPathRequestMatcher(this.adminServer.getContextPath() + "/actuator/**")))
.httpBasic() .rememberMe(rememberMe -> rememberMe.key(UUID.randomUUID()
.and() .toString())
.csrf() .tokenValiditySeconds(1209600));
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances", HttpMethod.POST.toString()), new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances/*", HttpMethod.DELETE.toString()),
new AntPathRequestMatcher(this.adminServer.getContextPath() + "/actuator/**"))
.and()
.rememberMe()
.key(UUID.randomUUID()
.toString())
.tokenValiditySeconds(1209600);
return http.build(); return http.build();
} }
} }

View File

@ -52,7 +52,7 @@ public class WebSecurityConfigIntegrationTest {
.password("admin")); .password("admin"));
mockMvc mockMvc
.perform(get("/applications/")) .perform(get("/applications"))
.andExpect(status().is2xxSuccessful()); .andExpect(status().is2xxSuccessful());
} }

View File

@ -49,4 +49,8 @@
</plugins> </plugins>
</build> </build>
<properties>
<start-class>com.baeldung.Application</start-class>
</properties>
</project> </project>

View File

@ -1,9 +1,9 @@
package com.baeldung.application.entities; package com.baeldung.application.entities;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.GenerationType; import jakarta.persistence.GenerationType;
import javax.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class User { public class User {

View File

@ -1,5 +1,22 @@
package com.baeldung.ecommerce.controller; package com.baeldung.ecommerce.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import com.baeldung.ecommerce.dto.OrderProductDto; import com.baeldung.ecommerce.dto.OrderProductDto;
import com.baeldung.ecommerce.exception.ResourceNotFoundException; import com.baeldung.ecommerce.exception.ResourceNotFoundException;
import com.baeldung.ecommerce.model.Order; import com.baeldung.ecommerce.model.Order;
@ -8,18 +25,8 @@ import com.baeldung.ecommerce.model.OrderStatus;
import com.baeldung.ecommerce.service.OrderProductService; import com.baeldung.ecommerce.service.OrderProductService;
import com.baeldung.ecommerce.service.OrderService; import com.baeldung.ecommerce.service.OrderService;
import com.baeldung.ecommerce.service.ProductService; import com.baeldung.ecommerce.service.ProductService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import javax.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/api/orders") @RequestMapping("/api/orders")

View File

@ -1,12 +1,13 @@
package com.baeldung.ecommerce.controller; package com.baeldung.ecommerce.controller;
import com.baeldung.ecommerce.model.Product;
import com.baeldung.ecommerce.service.ProductService;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull; import com.baeldung.ecommerce.model.Product;
import com.baeldung.ecommerce.service.ProductService;
import jakarta.validation.constraints.NotNull;
@RestController @RestController
@RequestMapping("/api/products") @RequestMapping("/api/products")

View File

@ -6,8 +6,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.validation.ConstraintViolation; import jakarta.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException; import jakarta.validation.ConstraintViolationException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,16 +1,22 @@
package com.baeldung.ecommerce.model; package com.baeldung.ecommerce.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
import javax.validation.Valid;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.validation.Valid;
@Entity @Entity
@Table(name = "orders") @Table(name = "orders")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="orderProducts") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="orderProducts")

View File

@ -2,10 +2,10 @@ package com.baeldung.ecommerce.model;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.Column; import jakarta.persistence.Column;
import javax.persistence.EmbeddedId; import jakarta.persistence.EmbeddedId;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.Transient; import jakarta.persistence.Transient;
@Entity @Entity
public class OrderProduct { public class OrderProduct {

View File

@ -1,13 +1,14 @@
package com.baeldung.ecommerce.model; package com.baeldung.ecommerce.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.Embeddable; import jakarta.persistence.Embeddable;
import javax.persistence.FetchType; import jakarta.persistence.FetchType;
import javax.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import javax.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import java.io.Serializable;
@Embeddable @Embeddable
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "order") @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "order")

View File

@ -1,7 +1,11 @@
package com.baeldung.ecommerce.model; package com.baeldung.ecommerce.model;
import javax.persistence.*; import jakarta.persistence.Basic;
import javax.validation.constraints.NotNull; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;
@Entity @Entity
public class Product { public class Product {

View File

@ -1,10 +1,11 @@
package com.baeldung.ecommerce.service; package com.baeldung.ecommerce.service;
import com.baeldung.ecommerce.model.OrderProduct;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid; import com.baeldung.ecommerce.model.OrderProduct;
import javax.validation.constraints.NotNull;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
@Validated @Validated
public interface OrderProductService { public interface OrderProductService {

View File

@ -1,10 +1,11 @@
package com.baeldung.ecommerce.service; package com.baeldung.ecommerce.service;
import com.baeldung.ecommerce.model.Order;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid; import com.baeldung.ecommerce.model.Order;
import javax.validation.constraints.NotNull;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
@Validated @Validated
public interface OrderService { public interface OrderService {

View File

@ -1,10 +1,11 @@
package com.baeldung.ecommerce.service; package com.baeldung.ecommerce.service;
import com.baeldung.ecommerce.model.Product;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.Min; import com.baeldung.ecommerce.model.Product;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
@Validated @Validated
public interface ProductService { public interface ProductService {

View File

@ -1,37 +1,37 @@
package com.baeldung.ecommerce; package com.baeldung.ecommerce;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collections;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import com.baeldung.ecommerce.controller.OrderController; import com.baeldung.ecommerce.controller.OrderController;
import com.baeldung.ecommerce.controller.ProductController; import com.baeldung.ecommerce.controller.ProductController;
import com.baeldung.ecommerce.dto.OrderProductDto; import com.baeldung.ecommerce.dto.OrderProductDto;
import com.baeldung.ecommerce.model.Order; import com.baeldung.ecommerce.model.Order;
import com.baeldung.ecommerce.model.Product; import com.baeldung.ecommerce.model.Product;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { EcommerceApplication.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = { EcommerceApplication.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class EcommerceApplicationIntegrationTest { public class EcommerceApplicationIntegrationTest {
@Autowired private TestRestTemplate restTemplate; @Autowired private TestRestTemplate restTemplate;
@LocalServerPort private int port; @LocalServerPort
private int port;
@Autowired private ProductController productController; @Autowired private ProductController productController;
@ -80,9 +80,7 @@ public class EcommerceApplicationIntegrationTest {
public void givenPostOrder_whenBodyRequestMatcherJson_thenResponseContainsEqualObjectProperties() { public void givenPostOrder_whenBodyRequestMatcherJson_thenResponseContainsEqualObjectProperties() {
final ResponseEntity<Order> postResponse = restTemplate.postForEntity("http://localhost:" + port + "/api/orders", prepareOrderForm(), Order.class); final ResponseEntity<Order> postResponse = restTemplate.postForEntity("http://localhost:" + port + "/api/orders", prepareOrderForm(), Order.class);
Order order = postResponse.getBody(); Order order = postResponse.getBody();
Assertions assertEquals(HttpStatus.CREATED, postResponse.getStatusCode());
.assertThat(postResponse.getStatusCode())
.isEqualByComparingTo(HttpStatus.CREATED);
assertThat(order, hasProperty("status", is("PAID"))); assertThat(order, hasProperty("status", is("PAID")));
assertThat(order.getOrderProducts(), hasItem(hasProperty("quantity", is(2)))); assertThat(order.getOrderProducts(), hasItem(hasProperty("quantity", is(2))));

View File

@ -39,6 +39,7 @@
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
<version>${hibernate.core.version}</version>
</dependency> </dependency>
<!--Test --> <!--Test -->
<dependency> <dependency>
@ -49,8 +50,15 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId> <artifactId>mockito-inline</artifactId>
<version>${mockito.inline.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<properties>
<hibernate.core.version>6.4.2.Final</hibernate.core.version>
<mockito.inline.version>5.2.0</mockito.inline.version>
<start-class>com.baeldung.annotations.VehicleFactoryApplication</start-class>
</properties>
</project> </project>

View File

@ -1,6 +1,5 @@
package com.baeldung.annotations; package com.baeldung.annotations;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
@DependsOn @DependsOn
@ -8,7 +7,10 @@ public class Bike implements Vehicle {
private String color; private String color;
@Required public Bike(String color) {
this.color = color;
}
public void setColor(String color) { public void setColor(String color) {
this.color = color; this.color = color;
} }

View File

@ -10,10 +10,9 @@
<description>This is simple boot application demonstrating a custom auto-configuration</description> <description>This is simple boot application demonstrating a custom auto-configuration</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -9,10 +9,9 @@
<description>Module For Spring Boot Basic Customization 2</description> <description>Module For Spring Boot Basic Customization 2</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -1,12 +1,13 @@
package com.baeldung.dispatchservlet.conf; package com.baeldung.dispatchservlet.conf;
import com.baeldung.dispatchservlet.listener.CustomListener;
import com.baeldung.dispatchservlet.servlet.CustomServlet;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.baeldung.dispatchservlet.listener.CustomListener;
import com.baeldung.dispatchservlet.servlet.CustomServlet;
import jakarta.servlet.ServletContextListener; import jakarta.servlet.ServletContextListener;
@Configuration @Configuration

View File

@ -1,11 +1,17 @@
package com.baeldung.dispatchservlet.filter; package com.baeldung.dispatchservlet.filter;
import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import jakarta.servlet.*; import jakarta.servlet.Filter;
import java.io.IOException; import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
@Component @Component
public class CustomFilter implements Filter { public class CustomFilter implements Filter {
@ -13,7 +19,7 @@ public class CustomFilter implements Filter {
Logger logger = LoggerFactory.getLogger(CustomFilter.class); Logger logger = LoggerFactory.getLogger(CustomFilter.class);
@Override @Override
public void init(FilterConfig filterConfig) throws ServletException { public void init(FilterConfig filterConfig) {
} }

View File

@ -1,15 +1,14 @@
package com.baeldung.dispatchservlet.servlet; package com.baeldung.dispatchservlet.servlet;
import com.baeldung.dispatchservlet.filter.CustomFilter; import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CustomServlet extends HttpServlet { public class CustomServlet extends HttpServlet {

View File

@ -1,5 +1,7 @@
package com.baeldung.onceperrequestfilter; package com.baeldung.onceperrequestfilter;
import java.io.IOException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
@ -7,7 +9,6 @@ import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component @Component
public class AuthenticationFilter extends OncePerRequestFilter { public class AuthenticationFilter extends OncePerRequestFilter {

View File

@ -1,5 +1,8 @@
package com.baeldung.onceperrequestfilter; package com.baeldung.onceperrequestfilter;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -7,8 +10,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Controller @Controller
public class HelloController implements AutoCloseable { public class HelloController implements AutoCloseable {
@ -18,7 +19,7 @@ public class HelloController implements AutoCloseable {
private Logger logger = LoggerFactory.getLogger(HelloController.class); private Logger logger = LoggerFactory.getLogger(HelloController.class);
@GetMapping(path = "/greeting") @GetMapping(path = "/greeting")
public DeferredResult<String> hello(HttpServletResponse response) throws Exception { public DeferredResult<String> hello(HttpServletResponse response) {
DeferredResult<String> deferredResult = new DeferredResult<>(); DeferredResult<String> deferredResult = new DeferredResult<>();
executorService.submit(() -> perform(deferredResult)); executorService.submit(() -> perform(deferredResult));
return deferredResult; return deferredResult;

View File

@ -1,5 +1,7 @@
package com.baeldung.onceperrequestfilter; package com.baeldung.onceperrequestfilter;
import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -9,7 +11,6 @@ import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component @Component
public class MyOncePerRequestFilter extends OncePerRequestFilter { public class MyOncePerRequestFilter extends OncePerRequestFilter {

View File

@ -9,10 +9,9 @@
<description>Module For Spring Boot Basic Customization</description> <description>Module For Spring Boot Basic Customization</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -1,5 +1,7 @@
package com.baeldung.bootcustomfilters.filters; package com.baeldung.bootcustomfilters.filters;
import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
@ -13,7 +15,6 @@ import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse; import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* A servlet filter to log request and response * A servlet filter to log request and response
@ -28,7 +29,7 @@ public class RequestResponseLoggingFilter implements Filter {
private final static Logger LOG = LoggerFactory.getLogger(RequestResponseLoggingFilter.class); private final static Logger LOG = LoggerFactory.getLogger(RequestResponseLoggingFilter.class);
@Override @Override
public void init(final FilterConfig filterConfig) { public void init(final FilterConfig filterConfig) throws ServletException {
LOG.info("Initializing filter :{}", this); LOG.info("Initializing filter :{}", this);
} }

View File

@ -1,5 +1,7 @@
package com.baeldung.bootcustomfilters.filters; package com.baeldung.bootcustomfilters.filters;
import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
@ -12,7 +14,6 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse; import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
/** /**
* A filter to create transaction before and commit it once request completes * A filter to create transaction before and commit it once request completes

View File

@ -9,10 +9,9 @@
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -12,4 +12,6 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
</project> </project>

View File

@ -1,7 +1,12 @@
package com.baeldung.data.jpa; package com.baeldung.data.jpa;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class ApplicationFound { public class ApplicationFound {
public static void main(String[] args) {
SpringApplication.run(ApplicationFound.class, args);
}
} }

View File

@ -0,0 +1,13 @@
package com.baeldung.data.jpa.library;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.data.jpa.libarary.model; package com.baeldung.data.jpa.library.model;
public class Example { public class Example {
private String example; private String example;

View File

@ -1,7 +0,0 @@
package com.baeldung.data.jpa;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
}

View File

@ -1,24 +1,23 @@
package com.baeldung.data.jpa.libarary; package com.baeldung.data.jpa.library;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@DataJpaTest @DataJpaTest
public class DataJpaUnitTest { @AutoConfigureDataJpa
class DataJpaUnitTest {
@Autowired @Autowired
private TestEntityManager entityManager; private TestEntityManager entityManager;
@Test @Test
public void givenACorrectSetup_thenAnEntityManagerWillBeAvailable() { void givenACorrectSetup_thenAnEntityManagerWillBeAvailable() {
assertNotNull(entityManager); assertNotNull(entityManager);
} }
} }

View File

@ -80,6 +80,7 @@
<properties> <properties>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version> <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
<start-class>com.baeldung.demo.DemoApplication,</start-class>
</properties> </properties>
</project> </project>

View File

@ -1,6 +1,6 @@
package com.baeldung.crud.controllers; package com.baeldung.crud.controllers;
import javax.validation.Valid; import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -1,10 +1,10 @@
package com.baeldung.crud.entities; package com.baeldung.crud.entities;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.GenerationType; import jakarta.persistence.GenerationType;
import javax.persistence.Id; import jakarta.persistence.Id;
import javax.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
@Entity @Entity
public class User { public class User {

View File

@ -2,9 +2,9 @@ package com.baeldung.demo.model;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class Foo implements Serializable { public class Foo implements Serializable {

View File

@ -1,8 +1,8 @@
package com.baeldung.entitydtodifferences.entity; package com.baeldung.entitydtodifferences.entity;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.Id; import jakarta.persistence.Id;
import javax.persistence.Table; import jakarta.persistence.Table;
@Entity @Entity
@Table(name = "books") @Table(name = "books")

View File

@ -4,13 +4,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.persistence.CascadeType; import jakarta.persistence.CascadeType;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.GenerationType; import jakarta.persistence.GenerationType;
import javax.persistence.Id; import jakarta.persistence.Id;
import javax.persistence.OneToMany; import jakarta.persistence.OneToMany;
import javax.persistence.Table; import jakarta.persistence.Table;
@Entity @Entity
@Table(name = "users") @Table(name = "users")

View File

@ -1,6 +1,6 @@
package com.baeldung.session.exception.repository; package com.baeldung.session.exception.repository;
import javax.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory;
import com.baeldung.demo.model.Foo; import com.baeldung.demo.model.Foo;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;

View File

@ -6,10 +6,9 @@
<artifactId>spring-boot-data-2</artifactId> <artifactId>spring-boot-data-2</artifactId>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -67,6 +67,7 @@
<properties> <properties>
<spring-cloud-starter-aws-secrets-manager-config.version>2.4.4</spring-cloud-starter-aws-secrets-manager-config.version> <spring-cloud-starter-aws-secrets-manager-config.version>2.4.4</spring-cloud-starter-aws-secrets-manager-config.version>
<aws-secretsmanager-jdbc.version>1.0.11</aws-secretsmanager-jdbc.version> <aws-secretsmanager-jdbc.version>1.0.11</aws-secretsmanager-jdbc.version>
<start-class>com.baeldung.startwithoutdb.StartWithoutDbApplication</start-class>
</properties> </properties>
</project> </project>

View File

@ -1,9 +1,9 @@
package com.baeldung.nopropertyfound.model; package com.baeldung.nopropertyfound.model;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.GenerationType; import jakarta.persistence.GenerationType;
import javax.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class Person { public class Person {

View File

@ -5,7 +5,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import javax.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
@SpringBootApplication @SpringBootApplication
@Profile("aws") @Profile("aws")

View File

@ -1,9 +1,9 @@
package com.baeldung.startdbwithawssecretsmanager.model; package com.baeldung.startdbwithawssecretsmanager.model;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.GenerationType; import jakarta.persistence.GenerationType;
import javax.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class UserEntity { public class UserEntity {

View File

@ -2,7 +2,7 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/myDb spring.datasource.url=jdbc:mysql://localhost:3306/myDb
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=root spring.datasource.password=root
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

View File

@ -1,13 +1,11 @@
package com.baeldung.startwithoutdb; package com.baeldung.startwithoutdb;
import javax.sql.DataSource;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import javax.sql.DataSource;
@SpringBootTest(classes = StartWithoutDbApplication.class) @SpringBootTest(classes = StartWithoutDbApplication.class)
class StartWithoutDbIntegrationTest { class StartWithoutDbIntegrationTest {
@ -16,7 +14,7 @@ class StartWithoutDbIntegrationTest {
private ApplicationContext context; private ApplicationContext context;
@Test @Test
public void givenAutoConfigDisabled_whenStarting_thenNoAutoconfiguredBeansInContext() { void givenAutoConfigDisabled_whenStarting_thenNoAutoconfiguredBeansInContext() {
context.getBean(DataSource.class); context.getBean(DataSource.class);
} }

View File

@ -159,6 +159,7 @@
<properties> <properties>
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version> <git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
<javafx.version>19</javafx.version> <javafx.version>19</javafx.version>
<start-class>com.baeldung.SpringBootDataApplication</start-class>
</properties> </properties>
</project> </project>

View File

@ -12,9 +12,8 @@ import com.baeldung.boot.jackson.model.Coffee;
public class CoffeeController { public class CoffeeController {
@GetMapping("/coffee") @GetMapping("/coffee")
public Coffee getCoffee( public Coffee getCoffee(@RequestParam(name = "brand", required = false) String brand,
@RequestParam(required = false) String brand, @RequestParam(name = "name", required = false) String name) {
@RequestParam(required = false) String name) {
return new Coffee().setBrand(brand) return new Coffee().setBrand(brand)
.setDate(FIXED_DATE) .setDate(FIXED_DATE)
.setName(name); .setName(name);

View File

@ -6,7 +6,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
@Component @Component
@Scope(value = "prototype") @Scope(value = "prototype")

View File

@ -7,7 +7,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import java.util.Arrays; import java.util.Arrays;
@Component @Component

View File

@ -7,7 +7,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;

View File

@ -7,7 +7,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;

View File

@ -1,6 +1,6 @@
package com.baeldung.gracefulshutdown.beans; package com.baeldung.gracefulshutdown.beans;
import javax.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -1,6 +1,6 @@
package com.baeldung.gracefulshutdown.config; package com.baeldung.gracefulshutdown.config;
import javax.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -1,6 +1,6 @@
package com.baeldung.shutdownhooks.beans; package com.baeldung.shutdownhooks.beans;
import javax.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -1,7 +1,7 @@
package com.baeldung.shutdownhooks.config; package com.baeldung.shutdownhooks.config;
import javax.servlet.ServletContextEvent; import jakarta.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import jakarta.servlet.ServletContextListener;
public class ExampleServletContextListener implements ServletContextListener { public class ExampleServletContextListener implements ServletContextListener {

View File

@ -1,6 +1,6 @@
package com.baeldung.shutdownhooks.config; package com.baeldung.shutdownhooks.config;
import javax.servlet.ServletContextListener; import jakarta.servlet.ServletContextListener;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;

View File

@ -11,10 +11,9 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3/pom.xml</relativePath>
</parent> </parent>
<dependencyManagement> <dependencyManagement>

View File

@ -9,10 +9,9 @@
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -32,4 +32,8 @@
</resources> </resources>
</build> </build>
<properties>
<start-class>com.baeldung.applicationcontextexception.MainEntryPoint</start-class>
</properties>
</project> </project>

View File

@ -51,7 +51,7 @@
</build> </build>
<properties> <properties>
<flowable.version>6.4.1</flowable.version> <flowable.version>7.0.1</flowable.version>
</properties> </properties>
</project> </project>

View File

@ -17,7 +17,7 @@ import org.springframework.boot.test.context.SpringBootTest;
@ExtendWith(FlowableSpringExtension.class) @ExtendWith(FlowableSpringExtension.class)
@SpringBootTest @SpringBootTest
public class ArticleWorkflowIntegrationTest { class ArticleWorkflowIntegrationTest {
@Autowired @Autowired
private RuntimeService runtimeService; private RuntimeService runtimeService;
@Autowired @Autowired

View File

@ -10,10 +10,9 @@
<description>Spring Boot GrralVM with Docker</description> <description>Spring Boot GrralVM with Docker</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -85,6 +85,7 @@
<properties> <properties>
<keycloak.version>21.0.1</keycloak.version> <keycloak.version>21.0.1</keycloak.version>
<start-class>com.baeldung.disablingkeycloak.App</start-class>
</properties> </properties>
</project> </project>

View File

@ -4,6 +4,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@Configuration @Configuration
@ -12,11 +13,9 @@ public class DisableSecurityConfiguration {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf() http.csrf(AbstractHttpConfigurer::disable)
.disable() .authorizeHttpRequests(request -> request.anyRequest()
.authorizeRequests() .permitAll());
.anyRequest()
.permitAll();
return http.build(); return http.build();
} }

View File

@ -3,8 +3,10 @@ package com.baeldung.disablingkeycloak;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer; import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
import org.springframework.security.core.session.SessionRegistryImpl; import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@ -23,12 +25,12 @@ public class KeycloakSecurityConfig {
@Bean @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf() http.csrf(AbstractHttpConfigurer::disable)
.disable()
.authorizeHttpRequests(auth -> auth.anyRequest() .authorizeHttpRequests(auth -> auth.anyRequest()
.authenticated()); .permitAll())
http.oauth2Login(); .oauth2Login(Customizer.withDefaults())
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt); .oauth2ResourceServer(httpSecurityOAuth2ResourceServerConfigurer ->
httpSecurityOAuth2ResourceServerConfigurer.jwt(Customizer.withDefaults()));
return http.build(); return http.build();
} }
} }

View File

@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
public class UserController { public class UserController {
@GetMapping("/{userId}") @GetMapping("/{userId}")
public User getCustomer(@PathVariable Long userId) { public User getCustomer(@PathVariable(name = "userId") Long userId) {
return new User(userId, "John", "Doe"); return new User(userId, "John", "Doe");
} }

View File

@ -3,8 +3,8 @@ package com.baeldung.keycloak.customendpoint;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException; import javax.ws.rs.NotFoundException;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;

View File

@ -1,9 +1,9 @@
package com.baeldung.keycloak; package com.baeldung.keycloak;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.GenerationType; import jakarta.persistence.GenerationType;
import javax.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class Customer { public class Customer {

View File

@ -10,8 +10,8 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@Component @Component
public class KeycloakLogoutHandler implements LogoutHandler { public class KeycloakLogoutHandler implements LogoutHandler {

View File

@ -3,14 +3,15 @@ package com.baeldung.keycloak;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
import org.springframework.security.core.session.SessionRegistryImpl; import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy; import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@ -29,18 +30,15 @@ class SecurityConfig {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests() return http.authorizeHttpRequests(request -> request.requestMatchers(new AntPathRequestMatcher("/customers*", "/users*"))
.antMatchers("/customers*", "/users*") .hasRole("USER")
.hasRole("USER") .anyRequest()
.anyRequest() .permitAll())
.permitAll(); .oauth2Login(Customizer.withDefaults())
http.oauth2Login() .logout(logout -> logout.addLogoutHandler(keycloakLogoutHandler)
.and() .logoutSuccessUrl("/"))
.logout() .oauth2ResourceServer(httpSecurityOAuth2ResourceServerConfigurer -> httpSecurityOAuth2ResourceServerConfigurer.jwt(Customizer.withDefaults()))
.addLogoutHandler(keycloakLogoutHandler) .build();
.logoutSuccessUrl("/");
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
return http.build();
} }
@Bean @Bean

View File

@ -8,7 +8,7 @@ import java.security.Principal;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@Controller @Controller
public class WebController { public class WebController {

View File

@ -11,10 +11,9 @@
<description>This is a simple application demonstrating integration between Keycloak and Spring Boot.</description> <description>This is a simple application demonstrating integration between Keycloak and Spring Boot.</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -6,7 +6,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.zalando.problem.spring.web.advice.security.SecurityProblemSupport; import org.zalando.problem.spring.web.advice.security.SecurityProblemSupport;
@Configuration @Configuration
@ -19,16 +21,11 @@ public class SecurityConfiguration {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf() return http.csrf(AbstractHttpConfigurer::disable)
.disable(); .authorizeHttpRequests(request -> request.requestMatchers(new AntPathRequestMatcher("/"))
.permitAll())
http.authorizeRequests() .exceptionHandling(exceptionHandling -> exceptionHandling.authenticationEntryPoint(problemSupport)
.antMatchers("/") .accessDeniedHandler(problemSupport))
.permitAll(); .build();
http.exceptionHandling()
.authenticationEntryPoint(problemSupport)
.accessDeniedHandler(problemSupport);
return http.build();
} }
} }

View File

@ -4,7 +4,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
/** /**
* Because the POM imports Spring Security, we need a simple security * Because the POM imports Spring Security, we need a simple security
@ -16,10 +18,9 @@ public class SecurityConfiguration {
@Bean @Bean
public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
http.csrf().disable(); return http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(request -> request.requestMatchers(new AntPathRequestMatcher("/**"))
return http.authorizeRequests() .permitAll())
.antMatchers("/**") .build();
.permitAll().and().build();
} }
} }

View File

@ -1,7 +1,7 @@
package com.baeldung.ratelimiting.bucket4japp.interceptor; package com.baeldung.ratelimiting.bucket4japp.interceptor;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;

View File

@ -1,7 +1,7 @@
package com.baeldung.toggle; package com.baeldung.toggle;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class Employee { public class Employee {

View File

@ -1,6 +1,6 @@
package com.baeldung.toggle; package com.baeldung.toggle;
import javax.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -9,10 +9,9 @@
<description>Demo project for Spring Boot Logging with Log4J2</description> <description>Demo project for Spring Boot Logging with Log4J2</description>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>parent-boot-3</artifactId> <artifactId>spring-boot-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -49,6 +49,11 @@
<artifactId>xstream</artifactId> <artifactId>xstream</artifactId>
<version>${xstream.version}</version> <version>${xstream.version}</version>
</dependency> </dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,11 +1,11 @@
package com.baeldung.mime; package com.baeldung.mime;
import javax.persistence.Column; import jakarta.persistence.Column;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import javax.persistence.GenerationType; import jakarta.persistence.GenerationType;
import javax.persistence.Id; import jakarta.persistence.Id;
import javax.persistence.Version; import jakarta.persistence.Version;
import java.io.Serializable; import java.io.Serializable;
@Entity @Entity

View File

@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@RestController @RestController
@RequestMapping(value = "/foos") @RequestMapping(value = "/foos")

View File

@ -1,10 +1,8 @@
package com.baeldung.students; package com.baeldung.students;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -16,14 +14,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import com.baeldung.students.StudentService;
@RestController @RestController
@RequestMapping("/students") @RequestMapping("/students")
public class StudentController { public class StudentController {
@Autowired private final StudentService service;
private StudentService service;
public StudentController(StudentService service) {
this.service = service;
}
@GetMapping("/") @GetMapping("/")
public List<Student> read() { public List<Student> read() {
@ -31,7 +30,7 @@ public class StudentController {
} }
@GetMapping("/{id}") @GetMapping("/{id}")
public ResponseEntity<Student> read(@PathVariable("id") Long id) { public ResponseEntity<Student> read(@PathVariable(name = "id") Long id) {
Student foundStudent = service.read(id); Student foundStudent = service.read(id);
if (foundStudent == null) { if (foundStudent == null) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
@ -41,7 +40,7 @@ public class StudentController {
} }
@PostMapping("/") @PostMapping("/")
public ResponseEntity<Student> create(@RequestBody Student student) throws URISyntaxException { public ResponseEntity<Student> create(@RequestBody Student student) {
Student createdStudent = service.create(student); Student createdStudent = service.create(student);
URI uri = ServletUriComponentsBuilder.fromCurrentRequest() URI uri = ServletUriComponentsBuilder.fromCurrentRequest()
@ -55,7 +54,7 @@ public class StudentController {
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public ResponseEntity<Student> update(@RequestBody Student student, @PathVariable Long id) { public ResponseEntity<Student> update(@RequestBody Student student, @PathVariable(name = "id") Long id) {
Student updatedStudent = service.update(id, student); Student updatedStudent = service.update(id, student);
if (updatedStudent == null) { if (updatedStudent == null) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
@ -65,10 +64,9 @@ public class StudentController {
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ResponseEntity<Object> deleteStudent(@PathVariable Long id) { public ResponseEntity<Object> deleteStudent(@PathVariable(name = "id") Long id) {
service.delete(id); service.delete(id);
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
} }
} }

View File

@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@ -45,6 +45,20 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<properties>
<start-class>com.baeldung.charencoding.CharacterEncodingDemo</start-class>
</properties>
</project> </project>

Some files were not shown because too many files have changed in this diff Show More