Difference between revisions of "Spring tips"

From DarkWiki
Jump to: navigation, search
(Noteworthy classes)
(Noteworthy classes)
Line 35: Line 35:
 
|-
 
|-
 
||ClassPathScanningCandidateComponentProvider||Used for scanning for annotated classes etc. See: https://gist.github.com/skempken/dbb2ad55d213cd6a1f50
 
||ClassPathScanningCandidateComponentProvider||Used for scanning for annotated classes etc. See: https://gist.github.com/skempken/dbb2ad55d213cd6a1f50
 +
|-
 +
||SpringDataWebProperties||A good example of how Spring configuration properties are bound from YML (etc.)
 
|}
 
|}

Revision as of 09:39, 5 June 2019

@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

Noteworthy classes

Class Notes
ClassPathScanningCandidateComponentProvider Used for scanning for annotated classes etc. See: https://gist.github.com/skempken/dbb2ad55d213cd6a1f50
SpringDataWebProperties A good example of how Spring configuration properties are bound from YML (etc.)