Difference between revisions of "Spring tips"
From DarkWiki
(→@Value) |
|||
| Line 1: | Line 1: | ||
==@Value== | ==@Value== | ||
| + | |||
| + | Simple setting of values. | ||
| + | |||
| + | <source lang="java"> | ||
| + | @Value("${prop.strName:default value}}") | ||
| + | private String localDir; | ||
| + | |||
| + | @Value("${prop.intName:14}}") | ||
| + | private int localDir; | ||
| + | </source> | ||
Apply a setting, defaulting to a subdirectory of the temporary folder. | Apply a setting, defaulting to a subdirectory of the temporary folder. | ||
Revision as of 10:05, 22 March 2018
@Value
Simple setting of values.
@Value("${prop.strName:default value}}")
private String localDir;
@Value("${prop.intName:14}}")
private int localDir;
Apply a setting, defaulting to a subdirectory of the temporary folder.
@Value("${prop.name:#{systemProperties['java.io.tmpdir']+'/subdir'}}")
private String localDir;
When a value is not present in the application.properties file, assume null.
@Value("${prop.name:#{null}}")
private String remoteUrl;
Configuration
A list of configuration properties can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html