Add startup checks

This commit is contained in:
2026-03-13 10:25:50 -06:00
parent 8368ff2359
commit 3cabc7b8ff
4 changed files with 47 additions and 0 deletions

21
pom.xml
View File

@@ -107,6 +107,27 @@
<release>25</release> <release>25</release>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>require-java-25</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[25,)</version>
<message>JDK 25 or newer is required. Configure IntelliJ and Maven to use JDK 25 before running the backend.</message>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>

View File

@@ -9,6 +9,7 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport;
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO) @EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
public class BackendApplication { public class BackendApplication {
public static void main(String[] args) { public static void main(String[] args) {
RuntimeClasspathValidator.validate();
new SpringApplicationBuilder(BackendApplication.class) new SpringApplicationBuilder(BackendApplication.class)
.initializers(new FlywayContextInitializer()) .initializers(new FlywayContextInitializer())
.run(args); .run(args);

View File

@@ -28,6 +28,7 @@ public class DevStackApplication {
try { try {
validateJavaVersion(); validateJavaVersion();
RuntimeClasspathValidator.validate();
docker.ensureDockerAvailable(); docker.ensureDockerAvailable();
docker.startDatabase(); docker.startDatabase();
context = new SpringApplicationBuilder(BackendApplication.class) context = new SpringApplicationBuilder(BackendApplication.class)

View File

@@ -0,0 +1,24 @@
package com.petshop.backend;
import java.net.URL;
final class RuntimeClasspathValidator {
private RuntimeClasspathValidator() {
}
static void validate() {
if (!resourceExists("application.yml")) {
throw new IllegalStateException("Backend resources are missing from the runtime classpath. Reimport the Maven project in IntelliJ and run the shared Maven run configuration.");
}
if (!resourceExists("db/migration/V1__baseline_schema.sql")) {
throw new IllegalStateException("Flyway migration files are missing from the runtime classpath. Reimport the Maven project in IntelliJ and run the shared Maven run configuration.");
}
}
private static boolean resourceExists(String path) {
ClassLoader classLoader = RuntimeClasspathValidator.class.getClassLoader();
URL resource = classLoader.getResource(path);
return resource != null;
}
}