Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : upgrade to spring boot 3.4.0-RC1 #1481

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jpa/boot-data-multipledatasources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0-RC1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>boot-data-multipledatasources</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>multipledatasources</name>
<name>boot-data-multipledatasources</name>
<description>Demo project for using multiple datasource's in a Spring Boot Application</description>

<properties>
Expand Down Expand Up @@ -220,7 +220,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.47.0</version>
<version>2.50.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.multipledatasources.bootstrap;

import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.example.multipledatasources.repository.member.MemberRepository;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.configuration;

import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.configuration;

import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.member.MemberRepository;
import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.multipledatasources.model.cardholder;
package com.example.multipledatasources.entities.cardholder;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.multipledatasources.model.member;
package com.example.multipledatasources.entities.member;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.repository.cardholder;

import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.repository.member;

import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.member.Member;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.multipledatasources.service.impl;

import com.example.multipledatasources.dto.ResponseDto;
import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.example.multipledatasources.repository.member.MemberRepository;
import com.example.multipledatasources.service.DetailsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,20 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.example.multipledatasources.common.ContainersConfiguration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = {ContainersConfiguration.class, MultipleDataSourcesApplication.class})
@AutoConfigureMockMvc
@Testcontainers(disabledWithoutDocker = true, parallel = true)
class ApplicationIntegrationTest {

@Container
private static final MySQLContainer<?> MY_SQL_CONTAINER = new MySQLContainer<>("mysql:9.0");

@Container
private static final PostgreSQLContainer<?> POSTGRE_SQL_CONTAINER =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:16.3-alpine"));

@DynamicPropertySource
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add("app.datasource.cardholder.url", MY_SQL_CONTAINER::getJdbcUrl);
registry.add("app.datasource.cardholder.username", MY_SQL_CONTAINER::getUsername);
registry.add("app.datasource.cardholder.password", MY_SQL_CONTAINER::getPassword);
registry.add("app.datasource.member.url", POSTGRE_SQL_CONTAINER::getJdbcUrl);
registry.add("app.datasource.member.username", POSTGRE_SQL_CONTAINER::getUsername);
registry.add("app.datasource.member.password", POSTGRE_SQL_CONTAINER::getPassword);
}

@Autowired
private MockMvc mockMvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
package com.example.multipledatasources;

import com.example.multipledatasources.common.ContainersConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration
public class TestMultipleDataSourcesApplication {

private static final MySQLContainer<?> MY_SQL_CONTAINER =
new MySQLContainer<>(DockerImageName.parse("mysql").withTag("9.1"));

private static final PostgreSQLContainer<?> POSTGRE_SQL_CONTAINER =
new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.0-alpine"));

static {
Startables.deepStart(MY_SQL_CONTAINER, POSTGRE_SQL_CONTAINER).join();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
MY_SQL_CONTAINER.stop();
POSTGRE_SQL_CONTAINER.stop();
}));
}
class TestMultipleDataSourcesApplication {

public static void main(String[] args) {
System.setProperty("app.datasource.cardholder.url", MY_SQL_CONTAINER.getJdbcUrl());
System.setProperty("app.datasource.cardholder.username", MY_SQL_CONTAINER.getUsername());
System.setProperty("app.datasource.cardholder.password", MY_SQL_CONTAINER.getPassword());
System.setProperty("app.datasource.member.url", POSTGRE_SQL_CONTAINER.getJdbcUrl());
System.setProperty("app.datasource.member.username", POSTGRE_SQL_CONTAINER.getUsername());
System.setProperty("app.datasource.member.password", POSTGRE_SQL_CONTAINER.getPassword());
SpringApplication.from(MultipleDataSourcesApplication::main)
.with(TestMultipleDataSourcesApplication.class)
.with(ContainersConfiguration.class)
.run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.example.multipledatasources.common;

import jakarta.annotation.PreDestroy;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistrar;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

/**
* Test configuration class that manages MySQL and PostgreSQL containers for integration testing.
* This class is responsible for starting the containers, registering their connection properties,
* and ensuring proper cleanup on shutdown.
*/
@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfiguration {

private MySQLContainer<?> mySQLContainer;
private PostgreSQLContainer<?> postgreSQLContainer;

@Bean
MySQLContainer<?> mySQLContainer() {
mySQLContainer = new MySQLContainer<>(DockerImageName.parse("mysql").withTag("9.1"));
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
mySQLContainer.start();
return mySQLContainer;
}
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved

@Bean
PostgreSQLContainer<?> postgreSQLContainer() {
postgreSQLContainer =
new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.0-alpine"));
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
postgreSQLContainer.start();
return postgreSQLContainer;
}

@Bean
public DynamicPropertyRegistrar databaseProperties(
MySQLContainer<?> mySQLContainer, PostgreSQLContainer<?> postgreSQLContainer) {
return (properties) -> {
// Connect our Spring application to our Testcontainers instances
properties.add("app.datasource.cardholder.url", mySQLContainer::getJdbcUrl);
properties.add("app.datasource.cardholder.username", mySQLContainer::getUsername);
properties.add("app.datasource.cardholder.password", mySQLContainer::getPassword);
properties.add("app.datasource.member.url", postgreSQLContainer::getJdbcUrl);
properties.add("app.datasource.member.username", postgreSQLContainer::getUsername);
properties.add("app.datasource.member.password", postgreSQLContainer::getPassword);
};
}

@PreDestroy
public void cleanup() {
if (mySQLContainer != null && mySQLContainer.isRunning()) {
mySQLContainer.stop();
}
if (postgreSQLContainer != null && postgreSQLContainer.isRunning()) {
postgreSQLContainer.stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(controllers = DetailsController.class)
Expand All @@ -20,7 +20,7 @@ class DetailsControllerTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
private DetailsService detailsService;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static org.mockito.BDDMockito.given;

import com.example.multipledatasources.dto.ResponseDto;
import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.example.multipledatasources.repository.member.MemberRepository;
import java.util.Optional;
Expand Down
2 changes: 1 addition & 1 deletion jpa/boot-jpa-locks/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'
services:

postgresqldb:
image: postgres:16.4-alpine
image: postgres:17.0-alpine
environment:
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=secret
Expand Down
25 changes: 23 additions & 2 deletions jpa/boot-jpa-locks/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.3.5</version>
<version>3.4.0-RC1</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the output, I can now generate the final response since I have enough information about the Spring Boot version usage across the codebase.

Spring Boot 3.4.0-RC1 upgrade needs to be consistent across modules

Several modules are still using Spring Boot 3.3.5 while others have been upgraded to 3.4.0-RC1. For consistency and to avoid potential compatibility issues, all modules should use the same Spring Boot version:

  • Modules using 3.4.0-RC1:

    • jpa/boot-jpa-locks
    • jpa/boot-data-multipledatasources
    • jpa/boot-hibernate2ndlevelcache-sample
    • r2dbc/boot-r2dbc-reactive-cache
    • boot-ultimate-redis
    • graphql/boot-graphql-querydsl
    • boot-grafana-lgtm
    • httpClients/boot-restclient
  • Modules still on 3.3.5:

    • scheduler/boot-scheduler-shedlock
    • r2dbc/boot-jooq-r2dbc-sample
    • r2dbc/boot-r2dbc-sample
    • scheduler/boot-scheduler-jobrunr
    • scheduler/boot-scheduler-quartz
    • open-api-spring-boot
    • jpa/multitenancy/*
    • boot-rest-docs-sample
    • boot-opensearch-sample
    • boot-rabbitmq-thymeleaf
    • boot-mongodb-elasticsearch
    • boot-togglz-sample
    • boot-choas-monkey
    • boot-api-archunit-sample
    • batch-boot-jpa-sample
🔗 Analysis chain

Verify compatibility with Spring Boot 3.4.0-RC1

While upgrading to RC versions can provide early access to new features, please ensure:

  1. All dependencies are compatible with this RC version
  2. This upgrade is suitable for your environment (RC versions aren't recommended for production)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential compatibility issues in dependencies
echo "Checking for Spring Boot managed dependencies..."
rg "spring-boot-starter-.*version" --type xml

echo "Checking for explicit version overrides that might conflict..."
rg "<version>.*</version>" --type xml

Length of output: 40767

<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.locks</groupId>
Expand Down Expand Up @@ -272,7 +272,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.47.0</version>
<version>2.50.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
Expand Down Expand Up @@ -385,4 +385,25 @@
</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 @@ -4,6 +4,7 @@

@UtilityClass
public final class AppConstants {
public static final String PROFILE_LOCAL = "local";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Consider replacing hardcoded "local" profile strings with AppConstants.PROFILE_LOCAL

Found multiple test applications using hardcoded "local" profile strings that could be replaced with the constant for consistency:

  • scheduler/boot-scheduler-quartz/src/test/java/com/scheduler/quartz/TestQuartzApplication.java
  • jpa/boot-hibernate2ndlevelcache-sample/src/test/java/com/example/hibernatecache/TestApplication.java
  • scheduler/boot-scheduler-shedlock/src/test/java/com/learning/shedlock/TestShedLockApplication.java
  • jpa/boot-data-envers/src/test/java/com/example/envers/TestApplication.java
  • jpa/boot-data-keyset-pagination/blaze-persistence/src/test/java/com/example/keysetpagination/TestApplication.java
  • graphql/boot-graphql-querydsl/src/test/java/com/example/graphql/querydsl/TestGraphQLQueryDSLApplication.java
  • boot-api-archunit-sample/src/test/java/com/example/archunit/TestApplication.java
🔗 Analysis chain

LGTM! Verify constant usage across the codebase.

The new constant follows the established naming pattern and best practices for utility classes.

Let's verify the constant usage and ensure no hardcoded "local" strings remain:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining hardcoded "local" profile strings that could be replaced with the constant

# Search for hardcoded "local" strings in profile-related contexts
rg -l --type java '"local"' | while read -r file; do
  if grep -l "spring.profiles" "$file" > /dev/null; then
    echo "Potential hardcoded profile in: $file"
    rg -A 2 -B 2 '"local"' "$file"
  fi
done

Length of output: 5417

public static final String PROFILE_PROD = "prod";
public static final String PROFILE_NOT_PROD = "!" + PROFILE_PROD;
public static final String PROFILE_TEST = "test";
Expand Down
2 changes: 2 additions & 0 deletions jpa/boot-jpa-locks/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ spring.jpa.show-sql=false
spring.jpa.open-in-view=false
spring.data.jpa.repositories.bootstrap-mode=deferred
spring.datasource.hikari.auto-commit=false
spring.datasource.hikari.pool-name=HikariPool-${spring.application.name}
spring.datasource.hikari.data-source-properties.ApplicationName=${spring.application.name}
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
spring.jpa.hibernate.ddl-auto=none
#spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package com.example.locks;

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

import com.example.locks.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.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.context.annotation.Import;

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

@Autowired
private DataSource dataSource;

@Test
void validateJpaMappingsWithDbSchema() {}
void validateJpaMappingsWithDbSchema() {
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.example.locks;

import com.example.locks.common.ContainersConfig;
import com.example.locks.utils.AppConstants;
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);
SpringApplication.from(Application::main)
.with(ContainersConfig.class)
.withAdditionalProfiles(AppConstants.PROFILE_LOCAL)
.run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class ContainersConfig {
@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("16.3-alpine"));
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.0-alpine"));
}
}
Loading