Skip to content

Commit

Permalink
fix : issue with running using java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Nov 4, 2023
1 parent e08e887 commit cc15533
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 86 deletions.
4 changes: 2 additions & 2 deletions scheduler/boot-scheduler-quartz/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM eclipse-temurin:17.0.8_7-jre-focal as builder
FROM eclipse-temurin:17.0.9_9-jre-focal as builder
WORKDIR application
ARG JAR_FILE=target/boot-scheduler-quartz-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

# the second stage of our build will copy the extracted layers
FROM eclipse-temurin:17.0.8_7-jre-focal
FROM eclipse-temurin:17.0.9_9-jre-focal
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
Expand Down
Empty file modified scheduler/boot-scheduler-quartz/mvnw
100644 → 100755
Empty file.
39 changes: 23 additions & 16 deletions scheduler/boot-scheduler-quartz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.5</version>
<version>3.2.0-RC2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.scheduler.quartz</groupId>
Expand All @@ -20,8 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>17</java.version>
<spring-cloud.version>2022.0.4</spring-cloud.version>
<java.version>21</java.version>
<springdoc-openapi.version>2.2.0</springdoc-openapi.version>
<commons-io.version>2.15.0</commons-io.version>

Expand Down Expand Up @@ -124,18 +123,6 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -237,7 +224,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.30.0</version>
<version>2.38.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
Expand Down Expand Up @@ -350,4 +337,24 @@
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,37 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
ProblemDetail onException(MethodArgumentNotValidException methodArgumentNotValidException) {
ProblemDetail problemDetail =
ProblemDetail.forStatusAndDetail(
HttpStatusCode.valueOf(400), "Invalid request content.");
ProblemDetail.forStatusAndDetail(HttpStatusCode.valueOf(400), "Invalid request content.");
problemDetail.setTitle("Constraint Violation");
List<ApiValidationError> validationErrorsList =
methodArgumentNotValidException.getAllErrors().stream()
.map(
objectError -> {
FieldError fieldError = (FieldError) objectError;
return new ApiValidationError(
fieldError.getObjectName(),
fieldError.getField(),
fieldError.getRejectedValue(),
Objects.requireNonNull(fieldError.getDefaultMessage(), ""));
})
.sorted(Comparator.comparing(ApiValidationError::field))
.toList();
List<ApiValidationError> validationErrorsList = methodArgumentNotValidException.getAllErrors().stream()
.map(objectError -> {
FieldError fieldError = (FieldError) objectError;
return new ApiValidationError(
fieldError.getObjectName(),
fieldError.getField(),
fieldError.getRejectedValue(),
Objects.requireNonNull(fieldError.getDefaultMessage(), ""));
})
.sorted(Comparator.comparing(ApiValidationError::field))
.toList();
problemDetail.setProperty("violations", validationErrorsList);
return problemDetail;
}

@ExceptionHandler(Exception.class)
ProblemDetail onException(Exception exception) {
if (exception instanceof ResourceNotFoundException resourceNotFoundException) {
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(
resourceNotFoundException.getHttpStatus(), resourceNotFoundException.getMessage());
problemDetail.setTitle("Not Found");
problemDetail.setType(URI.create("http://api.boot-scheduler-quartz.com/errors/not-found"));
problemDetail.setProperty("errorCategory", "Generic");
problemDetail.setProperty("timestamp", Instant.now());
return problemDetail;
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(
resourceNotFoundException.getHttpStatus(), resourceNotFoundException.getMessage());
problemDetail.setTitle("Not Found");
problemDetail.setType(URI.create("http://api.boot-scheduler-quartz.com/errors/not-found"));
problemDetail.setProperty("errorCategory", "Generic");
problemDetail.setProperty("timestamp", Instant.now());
return problemDetail;
} else {
return ProblemDetail.forStatusAndDetail(HttpStatusCode.valueOf(500), exception.getMessage());
}
}

record ApiValidationError(String object, String field, Object rejectedValue, String message) {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@OpenAPIDefinition(
info = @Info(title = "boot-scheduler-quartz", version = "v1"),
servers = @Server(url = "/"))
@OpenAPIDefinition(info = @Info(title = "boot-scheduler-quartz", version = "v1"), servers = @Server(url = "/"))
public class SwaggerConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ public LoggingAspect(Environment env) {
this.env = env;
}

@Pointcut(
"within(@org.springframework.stereotype.Repository *)"
+ " || within(@org.springframework.stereotype.Service *)"
+ " || within(@org.springframework.web.bind.annotation.RestController *)")
@Pointcut("within(@org.springframework.stereotype.Repository *)"
+ " || within(@org.springframework.stereotype.Service *)"
+ " || within(@org.springframework.web.bind.annotation.RestController *)")
public void springBeanPointcut() {
// pointcut definition
}

@Pointcut(
"@within(com.scheduler.quartz.config.logging.Loggable) || "
+ "@annotation(com.scheduler.quartz.config.logging.Loggable)")
@Pointcut("@within(com.scheduler.quartz.config.logging.Loggable) || "
+ "@annotation(com.scheduler.quartz.config.logging.Loggable)")
public void applicationPackagePointcut() {
// pointcut definition
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.scheduler.quartz.exception;

import lombok.Getter;
import org.springframework.http.HttpStatus;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package com.scheduler.quartz.model.response;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

import org.springframework.data.domain.Page;

public record PagedResult<T>(
List<T> data,
long totalElements,
int pageNumber,
int totalPages,
@JsonProperty("isFirst")
boolean isFirst,
@JsonProperty("isLast")
boolean isLast,
@JsonProperty("hasNext")
boolean hasNext,
@JsonProperty("hasPrevious")
boolean hasPrevious
) {
@JsonProperty("isFirst") boolean isFirst,
@JsonProperty("isLast") boolean isLast,
@JsonProperty("hasNext") boolean hasNext,
@JsonProperty("hasPrevious") boolean hasPrevious) {
public <R> PagedResult(Page<R> page, List<T> data) {
this(data,
this(
data,
page.getTotalElements(),
page.getNumber() + 1,
page.getTotalPages(),
Expand All @@ -30,4 +24,4 @@ public <R> PagedResult(Page<R> page, List<T> data) {
page.hasNext(),
page.hasPrevious());
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.boot.SpringApplication;

public class TestApplication {

public static void main(String[] args) {
System.setProperty("spring.profiles.active", "local");
SpringApplication.from(Application::main).with(ContainersConfig.class).run(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import org.springframework.test.web.servlet.MockMvc;

@ActiveProfiles({PROFILE_TEST})
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = {ContainersConfig.class})
@SpringBootTest(
webEnvironment = RANDOM_PORT,
classes = {ContainersConfig.class})
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {

@Autowired protected MockMvc mockMvc;
@Autowired
protected MockMvc mockMvc;

@Autowired protected ObjectMapper objectMapper;
@Autowired
protected ObjectMapper objectMapper;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class ContainersConfig {

@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:16.0-alpine"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.scheduler.quartz;

import static org.assertj.core.api.Assertions.assertThat;

import com.scheduler.quartz.common.ContainersConfig;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;

@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate", "spring.test.database.replace=none"})
@ImportTestcontainers(ContainersConfig.class)
class SchemaValidationTest {

@Autowired
private DataSource dataSource;

@Test
void validateJpaMappingsWithDbSchema() {
assertThat(dataSource).isNotNull().isInstanceOf(HikariDataSource.class);
}
}

0 comments on commit cc15533

Please sign in to comment.