Add startup checks
This commit is contained in:
21
pom.xml
21
pom.xml
@@ -107,6 +107,27 @@
|
||||
<release>25</release>
|
||||
</configuration>
|
||||
</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>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
||||
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
|
||||
public class BackendApplication {
|
||||
public static void main(String[] args) {
|
||||
RuntimeClasspathValidator.validate();
|
||||
new SpringApplicationBuilder(BackendApplication.class)
|
||||
.initializers(new FlywayContextInitializer())
|
||||
.run(args);
|
||||
|
||||
@@ -28,6 +28,7 @@ public class DevStackApplication {
|
||||
|
||||
try {
|
||||
validateJavaVersion();
|
||||
RuntimeClasspathValidator.validate();
|
||||
docker.ensureDockerAvailable();
|
||||
docker.startDatabase();
|
||||
context = new SpringApplicationBuilder(BackendApplication.class)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user