Java 28951 :- Upgrade spring-boot-rest to Spring Boot 3 (#15617)

This commit is contained in:
Amit Pandey 2024-01-22 18:05:02 +05:30 committed by GitHub
parent bcab98e9c1
commit e13051aff4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 73 additions and 80 deletions

View File

@ -11,9 +11,9 @@
<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>
<dependencies>
@ -144,8 +144,8 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb-runtime.version}</version>
</dependency>
</dependencies>
@ -164,6 +164,6 @@
<xstream.version>1.4.11.1</xstream.version>
<modelmapper.version>3.2.0</modelmapper.version>
<rest-assured.version>3.3.0</rest-assured.version>
<jaxb-runtime.version>2.3.7</jaxb-runtime.version>
<jaxb-runtime.version>4.0.1</jaxb-runtime.version>
</properties>
</project>

View File

@ -2,12 +2,12 @@ package com.baeldung.persistence.model;
import java.io.Serializable;
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 com.thoughtworks.xstream.annotations.XStreamAlias;
@ -16,7 +16,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
public class Foo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
import com.baeldung.persistence.IOperations;
@ -57,6 +57,6 @@ public abstract class AbstractService<T extends Serializable> implements IOperat
getDao().deleteById(entityId);
}
protected abstract PagingAndSortingRepository<T, Long> getDao();
protected abstract JpaRepository<T, Long> getDao();
}

View File

@ -1,19 +1,17 @@
package com.baeldung.persistence.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baeldung.persistence.dao.IFooDao;
import com.baeldung.persistence.model.Foo;
import com.baeldung.persistence.service.IFooService;
import com.baeldung.persistence.service.common.AbstractService;
import com.google.common.collect.Lists;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
@ -29,7 +27,7 @@ public class FooService extends AbstractService<Foo> implements IFooService {
// API
@Override
protected PagingAndSortingRepository<Foo, Long> getDao() {
protected JpaRepository<Foo, Long> getDao() {
return dao;
}

View File

@ -2,16 +2,16 @@ package com.baeldung.springpagination.model;
import java.util.Date;
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 Post {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;

View File

@ -1,15 +1,15 @@
package com.baeldung.springpagination.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 Preference {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String timezone;

View File

@ -1,10 +1,10 @@
package com.baeldung.springpagination.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class Subject {

View File

@ -1,16 +1,16 @@
package com.baeldung.springpagination.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;

View File

@ -4,7 +4,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import com.baeldung.springpagination.model.Post;

View File

@ -42,6 +42,6 @@ public class PostService implements IPostService {
@Override
public Post getPostById(Long id) {
return postRepository.getOne(id);
return postRepository.getReferenceById(id);
}
}

View File

@ -2,7 +2,7 @@ package com.baeldung.web.config;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;

View File

@ -2,7 +2,7 @@ package com.baeldung.web.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -2,8 +2,8 @@ package com.baeldung.web.controller;
import java.net.URI;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;

View File

@ -19,7 +19,7 @@ public class StudentService {
new Student(2, "Sebastian","Bach"),
new Student(3, "Pablo","Picasso"),
}).stream()
.collect(Collectors.toConcurrentMap(s -> s.getId(), Function.identity()));
.collect(Collectors.toConcurrentMap(Student::getId, Function.identity()));
// DB id sequence mock
private AtomicLong sequence = new AtomicLong(3);

View File

@ -1,13 +1,14 @@
package com.baeldung.web.error;
import javax.persistence.EntityNotFoundException;
import com.baeldung.web.exception.MyResourceNotFoundException;
import jakarta.persistence.EntityNotFoundException;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
@ -16,8 +17,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import com.baeldung.web.exception.MyResourceNotFoundException;
@ControllerAdvice
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
@ -42,14 +41,14 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH
}
@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(final HttpMessageNotReadableException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
final String bodyOfResponse = "This should be application specific";
// ex.getCause() instanceof JsonMappingException, JsonParseException // for additional information later on
return handleExceptionInternal(ex, bodyOfResponse, headers, HttpStatus.BAD_REQUEST, request);
}
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(final MethodArgumentNotValidException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
protected ResponseEntity<Object> handleMethodArgumentNotValid(final MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
final String bodyOfResponse = "This should be application specific";
return handleExceptionInternal(ex, bodyOfResponse, headers, HttpStatus.BAD_REQUEST, request);
}

View File

@ -3,8 +3,8 @@ package com.baeldung.web.error;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -2,7 +2,7 @@ package com.baeldung.web.hateoas.event;
import java.io.Serializable;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationEvent;
import org.springframework.web.util.UriComponentsBuilder;

View File

@ -1,6 +1,6 @@
package com.baeldung.web.hateoas.event;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationEvent;

View File

@ -1,6 +1,6 @@
package com.baeldung.web.hateoas.event;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationEvent;

View File

@ -2,7 +2,7 @@ package com.baeldung.web.hateoas.listener;
import java.util.StringJoiner;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

View File

@ -1,17 +1,14 @@
package com.baeldung.web.hateoas.listener;
import java.net.URI;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpHeaders;
import com.baeldung.web.hateoas.event.ResourceCreatedEvent;
import com.google.common.base.Preconditions;
import java.net.URI;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpHeaders;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import com.google.common.base.Preconditions;
@Component
class ResourceCreatedDiscoverabilityListener implements ApplicationListener<ResourceCreatedEvent> {

View File

@ -1,6 +1,6 @@
package com.baeldung.web.hateoas.listener;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import com.baeldung.web.hateoas.event.SingleResourceRetrievedEvent;
import com.baeldung.web.util.LinkUtil;

View File

@ -1,6 +1,6 @@
package com.baeldung.web.util;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
/**
* Provides some constants and utility methods to build a Link Header to be stored in the {@link HttpServletResponse} object

View File

@ -9,7 +9,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.Serializable;

View File

@ -4,7 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.Serializable;

View File

@ -3,7 +3,7 @@ package com.baeldung.rest;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;

View File

@ -86,7 +86,7 @@ public class CustomerControllerIntegrationTest {
List<Order> orders = Collections.singletonList(order1);
given(this.orderService.getAllOrdersForCustomer(DEFAULT_CUSTOMER_ID)).willReturn(orders);
this.mvc.perform(get("/customers/").accept(MediaTypes.HAL_JSON_VALUE))
this.mvc.perform(get("/customers").accept(MediaTypes.HAL_JSON_VALUE))
.andExpect(status().isOk())
.andExpect(
jsonPath("$._embedded.customers[0]._links.self.href", is("http://localhost/customers/customer1")))

View File

@ -29,7 +29,7 @@ public class FooControllerCustomEtagIntegrationTest {
@Autowired
private MockMvc mvc;
private String FOOS_ENDPOINT = "/foos/";
private String FOOS_ENDPOINT = "/foos";
private String CUSTOM_ETAG_ENDPOINT_SUFFIX = "/custom-etag";
private static String serializeFoo(Foo foo) throws Exception {

View File

@ -4,7 +4,7 @@ import static com.baeldung.Consts.APPLICATION_PORT;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import com.baeldung.common.web.AbstractLiveTest;
import com.baeldung.persistence.model.Foo;

View File

@ -5,7 +5,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.List;