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>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
<relativePath>../parent-boot-3</relativePath>
</parent>
<modules>
<module>spring-boot-admin</module>
<module>spring-boot-angular</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-2</module>
<module>spring-boot-autoconfiguration</module>
@ -31,33 +31,33 @@
<module>spring-boot-config-jpa-error</module>
<module>spring-boot-ctx-fluent</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-ci-cd</module>
<!-- <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-data</module>
<module>spring-boot-environment</module>
<module>spring-boot-exceptions</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-gradle</module> --> <!-- Not a maven project -->
<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-2</module>
<module>spring-boot-libraries</module>
<module>spring-boot-libraries-2</module>
<!-- <module>spring-boot-libraries</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-boot-libraries-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-process-automation</module>
<module>spring-boot-logging-logback</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-3</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-jersey</module>
<module>spring-boot-nashorn</module>
@ -65,34 +65,34 @@
<module>spring-boot-performance</module>
<module>spring-boot-property-exp</module>
<module>spring-boot-request-params</module>
<module>spring-boot-runtime</module>
<module>spring-boot-runtime-2</module>
<!-- <module>spring-boot-runtime</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-boot-runtime-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-security</module>
<module>spring-boot-security-2</module>
<module>spring-boot-ssl-bundles</module>
<module>spring-boot-telegram</module>
<module>spring-boot-springdoc</module>
<module>spring-boot-swagger</module>
<module>spring-boot-swagger-2</module>
<!-- <module>spring-boot-springdoc</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-boot-swagger</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <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-keycloak</module>
<module>spring-boot-swagger-springfox</module>
<module>spring-boot-testing</module>
<module>spring-boot-testing-2</module>
<!-- <module>spring-boot-testing</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-boot-testing-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<module>spring-boot-testing-spock</module>
<module>spring-boot-vue</module>
<module>spring-boot-actuator</module>
<module>spring-boot-data-2</module>
<module>spring-boot-validation</module>
<module>spring-boot-data-3</module>
<module>spring-caching</module>
<module>spring-caching-2</module>
<module>spring-boot-redis</module>
<!-- <module>spring-caching</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-caching-2</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<!-- <module>spring-boot-redis</module>--> <!-- failing after upgrading to spring boot 3.2.x -->
<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-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-test-pitfalls</module>
<module>spring-boot-3-testcontainers</module>
@ -100,10 +100,10 @@
<module>spring-boot-resilience4j</module>
<module>spring-boot-properties</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-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-mvc-legacy</module>
<module>spring-boot-springdoc-2</module>

View File

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

View File

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

View File

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

View File

@ -3,17 +3,15 @@
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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-3-grpc</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>spring-boot-3-grpc</name>
<packaging>pom</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modules>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,22 @@
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.exception.ResourceNotFoundException;
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.OrderService;
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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import jakarta.validation.constraints.NotNull;
@RestController
@RequestMapping("/api/orders")

View File

@ -1,12 +1,13 @@
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.RequestMapping;
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
@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.RestControllerAdvice;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,16 +1,22 @@
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.util.ArrayList;
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
@Table(name = "orders")
@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 javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Transient;
import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.Transient;
@Entity
public class OrderProduct {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,37 +1,37 @@
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.ProductController;
import com.baeldung.ecommerce.dto.OrderProductDto;
import com.baeldung.ecommerce.model.Order;
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)
public class EcommerceApplicationIntegrationTest {
@Autowired private TestRestTemplate restTemplate;
@LocalServerPort private int port;
@LocalServerPort
private int port;
@Autowired private ProductController productController;
@ -80,9 +80,7 @@ public class EcommerceApplicationIntegrationTest {
public void givenPostOrder_whenBodyRequestMatcherJson_thenResponseContainsEqualObjectProperties() {
final ResponseEntity<Order> postResponse = restTemplate.postForEntity("http://localhost:" + port + "/api/orders", prepareOrderForm(), Order.class);
Order order = postResponse.getBody();
Assertions
.assertThat(postResponse.getStatusCode())
.isEqualByComparingTo(HttpStatus.CREATED);
assertEquals(HttpStatus.CREATED, postResponse.getStatusCode());
assertThat(order, hasProperty("status", is("PAID")));
assertThat(order.getOrderProducts(), hasItem(hasProperty("quantity", is(2))));

View File

@ -39,6 +39,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.core.version}</version>
</dependency>
<!--Test -->
<dependency>
@ -49,8 +50,15 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.inline.version}</version>
<scope>test</scope>
</dependency>
</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>

View File

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

View File

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

View File

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

View File

@ -1,12 +1,13 @@
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.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.dispatchservlet.listener.CustomListener;
import com.baeldung.dispatchservlet.servlet.CustomServlet;
import jakarta.servlet.ServletContextListener;
@Configuration

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
package com.baeldung.bootcustomfilters.filters;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
@ -13,7 +15,6 @@ import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 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);
@Override
public void init(final FilterConfig filterConfig) {
public void init(final FilterConfig filterConfig) throws ServletException {
LOG.info("Initializing filter :{}", this);
}

View File

@ -1,5 +1,7 @@
package com.baeldung.bootcustomfilters.filters;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
@ -12,7 +14,6 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* 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>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>

View File

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

View File

@ -1,7 +1,12 @@
package com.baeldung.data.jpa;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
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,7 +0,0 @@
package com.baeldung.data.jpa;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
}

View File

@ -1,23 +1,22 @@
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.runner.RunWith;
import org.junit.jupiter.api.Test;
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.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@DataJpaTest
public class DataJpaUnitTest {
@AutoConfigureDataJpa
class DataJpaUnitTest {
@Autowired
private TestEntityManager entityManager;
@Test
public void givenACorrectSetup_thenAnEntityManagerWillBeAvailable() {
void givenACorrectSetup_thenAnEntityManagerWillBeAvailable() {
assertNotNull(entityManager);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -67,6 +67,7 @@
<properties>
<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>
<start-class>com.baeldung.startwithoutdb.StartWithoutDbApplication</start-class>
</properties>
</project>

View File

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

View File

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

View File

@ -1,9 +1,9 @@
package com.baeldung.startdbwithawssecretsmanager.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
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.username=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.properties.hibernate.temp.use_jdbc_metadata_defaults=false

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ 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.boot.test.web.server.LocalServerPort;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
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.boot.test.context.SpringBootTest;
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.test.context.junit4.SpringRunner;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -85,6 +85,7 @@
<properties>
<keycloak.version>21.0.1</keycloak.version>
<start-class>com.baeldung.disablingkeycloak.App</start-class>
</properties>
</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.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@ -12,11 +13,9 @@ public class DisableSecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf()
.disable()
.authorizeRequests()
.anyRequest()
.permitAll();
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(request -> request.anyRequest()
.permitAll());
return http.build();
}

View File

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

View File

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

View File

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

View File

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

View File

@ -10,8 +10,8 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@Component
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.Configuration;
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.web.builders.HttpSecurity;
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.web.SecurityFilterChain;
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@Configuration
@EnableWebSecurity
@ -29,18 +30,15 @@ class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/customers*", "/users*")
return http.authorizeHttpRequests(request -> request.requestMatchers(new AntPathRequestMatcher("/customers*", "/users*"))
.hasRole("USER")
.anyRequest()
.permitAll();
http.oauth2Login()
.and()
.logout()
.addLogoutHandler(keycloakLogoutHandler)
.logoutSuccessUrl("/");
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
return http.build();
.permitAll())
.oauth2Login(Customizer.withDefaults())
.logout(logout -> logout.addLogoutHandler(keycloakLogoutHandler)
.logoutSuccessUrl("/"))
.oauth2ResourceServer(httpSecurityOAuth2ResourceServerConfigurer -> httpSecurityOAuth2ResourceServerConfigurer.jwt(Customizer.withDefaults()))
.build();
}
@Bean

View File

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

View File

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

View File

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

View File

@ -4,7 +4,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.configurers.AbstractHttpConfigurer;
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
@ -16,10 +18,9 @@ public class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
http.csrf().disable();
return http.authorizeRequests()
.antMatchers("/**")
.permitAll().and().build();
return http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(request -> request.requestMatchers(new AntPathRequestMatcher("/**"))
.permitAll())
.build();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,11 @@
package com.baeldung.mime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Version;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Version;
import java.io.Serializable;
@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.server.ResponseStatusException;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
@RestController
@RequestMapping(value = "/foos")

View File

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

View File

@ -45,6 +45,20 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</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>
<properties>
<start-class>com.baeldung.charencoding.CharacterEncodingDemo</start-class>
</properties>
</project>

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