Spring-Boot: Accessing Properties
If you are using spring-boot and want to access properties from your properties- or yaml-file you can do that like this:
package xxx.xxx.security.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Configuration
@ConfigurationProperties("security.jwt")
public class JWTProperties {
private String secretKey;
}
In order for those entries to be accessable in the editor you have to add following dependency:
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
And to add following plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.0</version> <!-- Ensure you are using version 3.12.0 or later -->
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version> <!-- Use your Spring Boot version -->
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
I'm using vs-code for development and warnings about unknown properties go away afterwards. Auto complete works for the path but not for the property itself. Maybe I'm missing something here, but it is good enough for me