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 |
---|
|
@Component
@RequiredArgsConstructor
public class Example {
private Environment env;
....
public void method(String pathPropertyName) {
.....
String path = env.getProperty(pathPropertyName);
.....
} |
...
Code Block |
---|
|
@Value("${security.enable-csrf:true}")
private boolean csrfEnabled = true; |
Other approach using property configuration.
Code Block |
---|
|
@Scheduled(
fixedRateString = "${runtime.participantParameters.heartBeatMs}",
initialDelayString = "${runtime.participantParameters.heartBeatMs}")
public void schedule() {
} |
...
Code Block |
---|
|
@NotNull
@ParameterGroupConstraint
private TopicParameterGroup topicParameterGroup; |
ClRuntimeParameterGroup defined before could be injected into components.
Code Block |
---|
|
@Component
@RequiredArgsConstructor
public class Example {
private ClRuntimeParameterGroup parameters;
....
public void method() {
.....
long heartBeatMs = parameters.getHeartBeatMs();
.....
} |