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

upgrade to springboot 3.4 #1535

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions batch-boot-jpa-sample/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ services:
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=appdb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U appuser -d appdb"]
interval: 10s
timeout: 5s
retries: 5
ports:
- "5432:5432"
networks:
Expand Down
7 changes: 4 additions & 3 deletions batch-boot-jpa-sample/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.6</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.bootbatchjpa</groupId>
Expand All @@ -22,7 +22,8 @@

<java.version>21</java.version>
<instancio.version>5.2.1</instancio.version>
<springdoc-openapi.version>2.6.0</springdoc-openapi.version>
<springdoc-openapi.version>2.7.0</springdoc-openapi.version>


<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<spotless.version>2.43.0</spotless.version>
Expand Down Expand Up @@ -242,7 +243,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.25.0</version>
<style>AOSP</style>
</googleJavaFormat>
<importOrder />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class})
public class Application {
public class BatchApplication {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(BatchApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.*;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.job.builder.JobBuilder;
Expand All @@ -23,6 +28,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.transaction.PlatformTransactionManager;

@Configuration(proxyBeanMethods = false)
Expand Down Expand Up @@ -59,7 +65,6 @@ Job allCustomersJob(
.start(step)
.incrementer(new RunIdIncrementer())
.listener(this)
.start(step)
.build();
}

Expand Down Expand Up @@ -94,7 +99,7 @@ JpaPagingItemReader<Customer> jpaPagingItemReader(
}

@Override
public void afterJob(JobExecution jobExecution) {
public void afterJob(@NonNull JobExecution jobExecution) {
if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
log.info("BATCH JOB COMPLETED SUCCESSFULLY");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void run(String... args) {
List<Customer> customerList =
Instancio.ofList(Customer.class)
.size(1000)
.ignore(field(Customer.class, "id"))
.generate(
field(Customer.class, "gender"), gen -> gen.oneOf("male", "female"))
.create();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.bootbatchjpa;

import com.example.bootbatchjpa.common.ContainersConfig;
import org.springframework.boot.SpringApplication;

public class TestBatchApplication {

public static void main(String[] args) {
SpringApplication.from(BatchApplication::main).with(ContainersConfig.class).run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.example.bootbatchjpa.utils.AppConstants.PROFILE_TEST;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.example.bootbatchjpa.TestApplication;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand All @@ -14,7 +13,7 @@
@ActiveProfiles({PROFILE_TEST})
@SpringBootTest(
webEnvironment = RANDOM_PORT,
classes = {TestApplication.class})
classes = {ContainersConfig.class})
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.bootbatchjpa.common;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfig {

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

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

import com.example.bootbatchjpa.common.TestContainersConfig;
import com.example.bootbatchjpa.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(TestContainersConfig.class)
@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
@Import(ContainersConfig.class)
@AutoConfigureTestDatabase
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential configuration conflict with @AutoConfigureTestDatabase.

The default behavior of @AutoConfigureTestDatabase might override the TestContainers configuration.

Add explicit configuration to prevent auto-configuration from replacing your container:

 @DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
 @Import(ContainersConfig.class)
-@AutoConfigureTestDatabase
+@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
@Import(ContainersConfig.class)
@AutoConfigureTestDatabase
@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
@Import(ContainersConfig.class)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)

class SchemaValidationTest {

@Autowired private DataSource dataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
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.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(controllers = CustomerController.class)
Expand All @@ -39,7 +39,7 @@ class CustomerControllerTest {

@Autowired private MockMvc mockMvc;

@MockBean private CustomerService customerService;
@MockitoBean private CustomerService customerService;

@Autowired private ObjectMapper objectMapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
class TestApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main).with(ContainersConfig.class).run(args);
SpringApplication.from(BatchApplication::main).with(ContainersConfig.class).run(args);
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
class TestApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main).with(ContainersConfig.class).run(args);
SpringApplication.from(BatchApplication::main).with(ContainersConfig.class).run(args);
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading