Spring documentation tells that, if we compile our project using Java 8 --parameters flag, we can skip giving parameter names in annotations like @PathVariable. That means, we can just use @PathVariable id
instead of @PathVariable("id") id
.
In a Spring Boot Maven application, I was curious to know how to tell the compiler to use the parameters flag. Is it on by default? Do we need to provide something in the pom.xml?
In Spring Boot 2.0, the
--parameters
flag should be enabled by default. See yuranos87's answer.For older versions, in the pom.xml file, you can specify Java compiler options as arguments of the Maven compiler plugin:
I don't remember needing to do it explicitly in any of my projects. Maybe you just need to add spring-boot-starter-parent(I know, sometimes might not be an option). Otherwise, Spring has already taken care of everything for you.
It is mentioned multiple times in Spring Boot documentation. For example, here:
UPDATE
The way Spring Boot does it is quite straight forward(in spring-boot-parent and spring-boot-starter-parent poms):