spring boot version 2.4.6

config.properties:

config.mail=xxx@xx.com
config.timeout=1000

Config.kt

@ConstructorBinding
@ConfigurationPropperties(prefix="config")
@PropertySource("classpath:config.properties")
data class Config (
    val mail:String,
    val timeout:Long
)

and use kapt("org.springframework.boot:spring-boot-configuration-processor") in gradle

but it fails with the following:

Description:

Failed to bind properties under 'config' to com.looptry.core.common.Config:

    Reason: Failed to bind properties under 'config' to com.looptry.core.common.Config

Action:

Update your application's configuration

Thanks for your response!

Comment From: hellomr3

if i remove @PropertySource and write properties in application.properties it's works well

Comment From: wilkinsona

We do not recommend using @PropertySource to customize the environment in a Spring Boot application. If you must use it, it should be used on a @Configuration class.

If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.