Skip to main content

2024-07-17

One-liner

I do not envy other people's lives, and that is what happiness is. --- Lucky Star · Sai


Java Code Example with @Value

For a requirement where you need to read values from a configuration file into a List<Integer> property, you can use the @Value annotation to achieve this.

YAML Configuration

api:
ids: 1,2,3

Java Code

@Value("#{'${api.ids}'.split(',')}")
private List<Integer> ids;
warning

If you use @Value("${api.ids}") directly, it will throw an error and fail to parse. However, it will work correctly if the type is List<String>.