Вы не можете / не должны изменять значения перечисления в Java.Попробуйте вместо этого использовать класс:
public class MyCustomProperty {
// can't change this in application.properties
private final String lowerCase;
// can change this in application.properties
private String atitude;
private long someNumber;
public MyCustomProperty (String lowerCase, String atitude, long someNumber) {
this.lowerCase = lowerCase;
this.atitude = atitude;
this.someNumber = someNumber;
}
// getter and Setters
}
Чем создать пользовательский ConfigurationProperties :
@ConfigurationProperties(prefix="my.config")
public class MyConfigConfigurationProperties {
MyCustomProperty name = new MyCustomProperty("name", "good", 100);
MyCustomProperty fame = new MyCustomProperty("fame", "good", 100);
// getter and Setters
// You can also embed the class MyCustomProperty here as a static class.
// For details/example look at the linked SpringBoot Documentation
}
Теперь вы можете изменять значения my.config.name.someNumber
и my.config.fame.someNumber
в файле application.properties.Если вы хотите запретить изменение строчных букв / символов, сделайте их окончательными.
Прежде чем вы сможете использовать его, вы должны аннотировать класс @Configuration
с помощью @EnableConfigurationProperties(MyConfigConfigurationProperties.class)
.Также добавьте org.springframework.boot:spring-boot-configuration-processor
в качестве необязательной зависимости для лучшей поддержки IDE.
Если вы хотите получить доступ к значениям:
@Autowired
MyConfigConfigurationProperties config;
...
config.getName().getSumeNumber();