This commit is contained in:
Anthony Stirling 2025-01-04 12:56:20 +00:00
parent 093b882141
commit cf03bdc17b
3 changed files with 12 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package stirling.software.SPDF;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -77,7 +78,14 @@ public class SPdfApplication {
props.put("spring.main.web-application-type", "servlet");
}
app.setAdditionalProfiles("default");
app.addInitializers(new ConfigInitializer());
ConfigInitializer initializer = new ConfigInitializer();
try {
initializer.ensureConfigExists();
} catch (IOException | URISyntaxException e) {
log.error("Error initialising configuration", e);
}
Map<String, String> propertyFiles = new HashMap<>();
// External config files
log.info("Settings file: {}", InstallationPathConfig.getSettingsPath());

View File

@ -22,18 +22,9 @@ import org.springframework.context.ConfigurableApplicationContext;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ConfigInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
public class ConfigInitializer {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
try {
log.info("Setting up configs from templates");
ensureConfigExists();
} catch (Exception e) {
throw new RuntimeException("Failed to initialize application configuration", e);
}
}
public void ensureConfigExists() throws IOException, URISyntaxException {
// Define the path to the external config directory
@ -54,6 +45,7 @@ public class ConfigInitializer
"Resource file not found: settings.yml.template");
}
}
log.info("Created settings file from template");
} else {
// Define the path to the config settings file

View File

@ -41,7 +41,6 @@ import stirling.software.SPDF.model.provider.UnsupportedProviderException;
@Configuration
@ConfigurationProperties(prefix = "")
@EnableConfigurationProperties(ApplicationProperties.class)
@Data
@Order(Ordered.HIGHEST_PRECEDENCE)
@Slf4j