You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+19-5Lines changed: 19 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,25 @@ This project covers several changes in spring-boot 2.0.0 which are worth knowing
4
4
5
5
Currently this project contains changes from the latest released milestone 2.0.0M3.
6
6
7
-
__Code structure__
7
+
__Code structure__<br/>
8
8
This repository contains two spring-boot-projects:
9
9
-`spring-boot-2-demo` which shows the new features, see below.
10
10
-`spring-boot-1-demo` which is meant to show the old behaviour
11
11
12
12
# Features inherited from Spring Framework 5.0.0
13
13
14
-
## @Nullable
15
-
See package `de.acando.jk.bootdemo.newfeatures.nullable`.
14
+
## @Nullable and @NonNullApi
16
15
17
-
`@Nullable` annotation can be used in controller to define that e.g. a RequestParam is not required.
16
+
> Intention of the spring developers was to "leverage [JSR 305](https://jcp.org/en/jsr/detail?id=305) (...) meta-annotations to specify explicitly
17
+
null-safety of Spring Framework parameters and return values", compare this [commit message](https://github.com/spring-projects/spring-framework/commit/87598f48e41d483745aba56cbf4e998c6f6d680c#diff-31f527c92f7d3887b2320e4a28e7be8a). <br/>
18
+
> Another aim was to make the Spring-Framework null-safe for Kotlin. The annotations are also used for static code analysis, e.g. IntelliJ produces warnings when unsafe nullable usages are detected.
19
+
20
+
Besides these points described above, the `@Nullable` annotation can be used to declare that a object can be null which means it is not required. Places where it can be used:
21
+
- On field injection
22
+
- On controller injection
23
+
- In controllers requestmapping methods to define that e.g. a RequestParam is not required.
24
+
25
+
Example implementation see package `newfeaturesin2.nullable` in both projects.
18
26
19
27
## Candidate Component Index
20
28
There is a new package `spring-context-indexer` which, if included as dependency, creates a index file `META-INF/spring.components` at build time. This file lists all candidate components (Spring Beans) as well as JPA candidates (Entities, Repositories).
@@ -26,13 +34,16 @@ Add following maven dependendy to active the new feature:
26
34
<artifactId>spring-context-indexer</artifactId>
27
35
</dependency>
28
36
37
+
For more details for this new feature see the [commit message](https://github.com/snicoll/spring-framework/commit/dc160f6fd1f3623bf14b375c14a9b5065e660377) and the [JIRA Discussion](https://jira.spring.io/browse/SPR-11890).
38
+
29
39
Simple hint for taking a look at the new mechanism via debugging in an IDE:
30
40
- CAUTION: This is just for taking a look at the new mechanism, should be reverted if going back to developing!
31
41
- Run a build, then copy `META-INF/spring.components` from the jar file to `src/main/resources/META-INF/spring.components`
32
42
- Breakpoints in
33
43
*`CandidateComponentsIndexLoader.loadIndex(..)` where the index file is loaded
34
44
*`ClassPathScanningCandidateComponentProvider.findCandidateComponents(..)` where the index is used ix exists, otherwise class path is scanned
35
45
46
+
To see that it works for JPA related candidates, checkout the branch `jpa` and run a build.
36
47
37
48
38
49
## Changed or removed properties
@@ -50,7 +61,10 @@ Simple hint for taking a look at the new mechanism via debugging in an IDE:
50
61
Can be changed with property `management.context-path`.
51
62
52
63
## @ConfigurationProperties needs @Validated
53
-
`@Valiadated` is now required, if there are any validation annotations in a `@ConfigurationProperties` class, which should be requested at startup.
64
+
65
+
`@Validated` is now required, if there are any validation annotations in a `@ConfigurationProperties` class, which should be requested at startup.
66
+
67
+
Example implementation: see package `newfeaturesin2.properties` in both projects. In v1.x the application fails starting, if the property `test.any` is not set. In v2.x it only fails if the `@Validated` annotation is used.
54
68
55
69
## New spring-boot-starter-json
56
70
Includes dependencies `jackson-databind`, `jackson-datatype-jsr310` (necessary for convenient handling of java 8 data types) among others. The `spring-boot-starter-json` is in 2.0.0 included everywhere, where `jackson-databind` was used in 1.x. E.g. in the `spring-boot-starter-web`, so for my normal project setup there is no jackson dependency to be added explicitly anymore.
0 commit comments