Tiago
01/16/2023, 5:23 PM@ConfigurationProperties("application.custom.properties")
data class SomeProperties(
val foo: Long,
val bar: String,
)
application.properties:
application.custom.properties.foo=1
application.custom.properties.bar=Text Here
ok, so I have another class, just a POJO, and need to get the values from that configuration properties bean
data class ObjectBuilder(
var fooValue: Long = SomeProperties.foo,
var barValue: String = SomeProperties.bar,
)
is there a way of getting the SomeProperties values on a non spring context?ashmelev
01/16/2023, 5:27 PM@Bean(name = ["objectBean"])
fun objectBean(): ObjectBuilder =
ObjectBuilder(
fooValue = SomeProperties.foo,
barValue = SomeProperties.bar
)
ashmelev
01/16/2023, 5:28 PMobjectBean
wherever you need itTiago
01/16/2023, 7:43 PM@Entity
data class EntityA(
var entityB: EntityB
)
@Entity
data class EntityB(
var foo: Long = SomeProperties.foo
)
I want to use the SomeProperties.foo
as the default value for EntityA.entityB.fooashmelev
01/16/2023, 9:23 PMobjectBean
. Try something like:
@Entity
@Component
data class EntityB(
@Transient private val objectBean: ObjectBuilder,
var foo: Long = objectBean.fooValue
)
Obviously I have not tested this so I am not sure it will actually inject properlykqr
01/17/2023, 8:50 AMTiago
01/17/2023, 9:14 AMTiago
01/17/2023, 9:15 AM@PostConstruct
fun initialize() {
instance = this
}
And then I can access this instance from a non-spring context
but I am not completely happy with this approach 😆kqr
01/17/2023, 9:50 AM@Component
class EntityBFactory(val config: SomeProperties) {
fun create(): EntityB = ...
}
ashmelev
01/17/2023, 3:45 PMTiago
01/17/2023, 4:45 PM