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
190 changed files with 1052 additions and 832 deletions
+25 -25
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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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/**")
.permitAll()
.antMatchers(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()
.toString())
.tokenValiditySeconds(1209600);
http.authorizeHttpRequests(req -> req.requestMatchers(this.adminServer.getContextPath() + "/assets/**")
.permitAll()
.requestMatchers(this.adminServer.getContextPath() + "/login")
.permitAll()
.anyRequest()
.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));
return http.build();
}
}
@@ -52,7 +52,7 @@ public class WebSecurityConfigIntegrationTest {
.password("admin"));
mockMvc
.perform(get("/applications/"))
.perform(get("/applications"))
.andExpect(status().is2xxSuccessful());
}
@@ -49,4 +49,8 @@
</plugins>
</build>
<properties>
<start-class>com.baeldung.Application</start-class>
</properties>
</project>
@@ -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 {
@@ -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")
@@ -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")
@@ -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;
@@ -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")
@@ -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 {
@@ -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")
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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))));
@@ -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>
@@ -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;
}
@@ -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>

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