`@Component @ConfigurationProperties() class PropH...
# spring
v
Copy code
@Component
@ConfigurationProperties()
class PropHldr {
    companion object {
        @Value("\${sipPropFiles}")
        lateinit var sipPropFile: String

    }


}
t
since the companion object is essentially a singleton object created outside of the spring context - autowiring for it needs to be called manually. You can grab a
AutowireCapableBeanFactory
from somewhere, e.g. by dependency injection or during
SpringApplication
setup and call
beanFactoryInstance.autowireBean(PropHldr.Companion)
v
Thank you, may be Companion Object is a wrong idea... all I wanted to do is
@Value("\${sipPropFile}")
read from the application.properties file..... the below is also not working
Copy code
@Configuration()

class Routing {

    @Value("\${sip.sipPropFile}")
    lateinit var sipPropFile: String
c
Also, for multi-line chunks of code you can use triple backticks 🙂
v
yep, thx
t
I think you have to define the path to the properties file for this to work. You can find an example in https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html, under the
Using the @Value annotation
heading
v
@PropertySource("classpath:application.properties")
did the trick 🙂
👍 1
@Tadas Giniotis the link you sent me helped
its a wonder when Spring Boot says -- its convention based and still makes you specify the properties file explicitly for the
@Configuration
annotation -- btw I was running the JUnit5 test case, this is where it originated
t
judging from this it should work without explicitly specifying the path - https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html