春季启动必须在应用程序之前创建文件。

发布于 2025-01-31 10:28:56 字数 313 浏览 3 评论 0原文

我目前正在从事一个Spring Boot项目,并且我们有一个应用程序。Properties文件,该文件定义了一个有2个JKS文件的路径。 (原始文件具有更多的键/值对,但是我重点放在这两个对的主要问题上)

示例

file1.example=folder/file1.jks
file12.example=folder/file2.jks

,但是现在,我需要读取一个包含我需要采用,解码和使用的编码值的环境变量创建这些文件。主要的问题是,我需要在“加载”属性之前创建这两个文件,因为这些文件不存在,如果我不首先构建它们,是否有任何想法?

I'm working currently on a Spring boot project, and we have an application.properties file that defines a path where we have 2 jks files. (the original file has more key/value pairs, but I'm focusing in the main problem with these two pairs)

example

file1.example=folder/file1.jks
file12.example=folder/file2.jks

But now, I need to read an environment variable that contains an encoded value that I need to take, decode and use to create these files. The main problem is that I need to create these two files before the properties are "loaded" because these files do not exist, if I first don't build them, any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿得七秒忆 2025-02-07 10:28:56

通常从以下主要方法启动Spring Boot。您可以在调用启动器之前定义静态方法,以便在该方法中使用所需的任何环境变量,并制作I/O操作来准备文件。然后,如果成功完成此操作,则可以让Spring Boot正常启动服务器和应用程序。

@SpringBootApplication
public class ConfigurationApplication {

    public static void main(String[] args) {
        createPropertiesFiles();   <---------------
        SpringApplication.run(ConfigurationApplication.class, args);
     }

    private static void createPropertiesFiles(){
        // I/O operations to create those files ...
    }

 }

Normally Spring boot launches from the following main method. You can define a static method before the launcher is called so that in that method you use whatever environment variable you want and make I/O operations to prepare the files. Then if this is done successfully you can let Spring Boot start the server and application normally.

@SpringBootApplication
public class ConfigurationApplication {

    public static void main(String[] args) {
        createPropertiesFiles();   <---------------
        SpringApplication.run(ConfigurationApplication.class, args);
     }

    private static void createPropertiesFiles(){
        // I/O operations to create those files ...
    }

 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文