Search code examples
springzeebe

passing toml file name to spring context


the zeebe-broker has to be started with the path to a configuration toml file. However, in a spring context, I only have this information at runtime (its a cli argument). How can I define my spring configuration (annotation based) to provide a bean for a broker that is initialized with the given path?


Solution

  • Found a solution: The command line args can be accessed in the following way:

     static Function<Environment, Optional<String>> tomlFileFromEnv = environment -> {
        String[] args = environment.getProperty("nonOptionArgs", String[].class, new String[0]);
        if (args == null || args.length == 0) {
            return Optional.empty();
        } else if (args.length > 1) {
            throw new IllegalArgumentException("requires exactly one cli argument, the tomlFile.");
        } else {
            return Optional.of(args[0]);
        }
    
    };