N
N
nuclear_kote2018-07-11 12:41:23
Java
nuclear_kote, 2018-07-11 12:41:23

How to get properties at runtime in spring?

there is a list of properties in the file property.name.0, property.name.1 ... property.name.N
how to get them?
Tried like this:

private final ClassPathXmlApplicationContext ctx;
 ...
 String prop = ctx.getBeanFactory().resolveEmbeddedValue("${property.name." + i + "}");

but if property.name.1 doesn't exist it crashes
ERROR java.lang.IllegalArgumentException: Could not resolve placeholder 'property.name.0' in value ${property.name.0}"

${property.name." + i + ":''} format expressions do not work.
spring clean, not boot

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-07-11
@EreminD

@Value("${property.name}")
private String propertyName;

not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question