Hello, I am trying to read properties but it never...
# spring
t
Hello, I am trying to read properties but it never returns the correct value. This is what I use
Copy code
@Component
@ConfigurationProperties
@PropertySource("classpath:app.properties")
class AppProperties {
    lateinit var mongoUri: String
    lateinit var manticoreEndpoint: String
    lateinit var manticorePlatform: String
    lateinit var manticoreUsername: String
    lateinit var manticorePassword: String
    lateinit var internalToken: String
}
My properties look like
Copy code
mongo-uri=""
mantictore-endpoint=""
I also added
@EnableConfigurationProperties
. I missed something? Thanks for your help.
j
does it help if you replace @Component with @Configuration
t
I just tried, the result is the same ­čś×
m
Try annotating the properties with
@Value("${mongo-uri}")
, etc
(Are they supposed to bind just by name?)
j
The one idea of @ConfigurationProperties is to get rid of using @Value, @ConfigurationProperties is actually a Spring Boot feature and not included in Spring Core
­čĹŹ 1
t
Even with
@Value
it doesn't work.
j
Maybe you should try some simple value first with prefix like
Copy code
app.foo = value
Then use
Copy code
@ConfigurationProperties(prefix = "app")
Copy code
lateinit var foo: String
also try leaving out
Copy code
@PropertySource("classpath:app.properties")
and use application.properties which should be the default
t
Hmm I applied all your suggestion, it still not working.
j
strange
t
I even tried to use
Environment
with
env.getProperty("mongo-uri")
, I could not get the value.
Maybe it's not related to Kotlin then. I will ask on StackOverflow then. Thanks for your help.
s
Share a project via GitHub, we will be able to see quickly what is the issue