Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Component uses Properties directly, performing type conversion and error checking as appropriate.

org.springframework.core.env.Environment is not a good approach, but it could be useful when the name of the property you need to access changes dynamically.

Code Block
languagejava
@Component
@RequiredArgsConstructor
public class Example {

private Environment env;
....

public void method(String pathPropertyName) {
    .....  
    String path = env.getProperty(pathPropertyName);
    .....
}

...

Code Block
languagejava
    @Value("${security.enable-csrf:true}")
    private boolean csrfEnabled = true;


Other approach using property configuration.

Code Block
languagejava
    @Scheduled(
            fixedRateString = "${runtime.participantParameters.heartBeatMs}",
            initialDelayString = "${runtime.participantParameters.heartBeatMs}")
    public void schedule() { 
}

...

Code Block
languagejava
    @NotNull
    @ParameterGroupConstraint
    private TopicParameterGroup topicParameterGroup;


ClRuntimeParameterGroup defined before could be injected into components.

Code Block
languagejava
@Component
@RequiredArgsConstructor
public class Example {
 
private ClRuntimeParameterGroup parameters;
....
 
public void method() {
    ..... 
    long heartBeatMs = parameters.getHeartBeatMs();
    .....
}