I met a issue,I try to listen to EnvironmentChangeEvent and re-init some configuration.
While i found that @Value annotation with SpEL is not working, but plain @Value annotation is OK:
@Component public class ConsumeService { @Autowired ConsumeConfig consumeConfig; @EventListener(EnvironmentChangeEvent.class) void onEnvChange() { log.debug("{}",consumeConfig); //when i print here, i get only consumeDesc, but cardList is an empty List. } } @Configuration @RefreshScope public class ConsumeConfig { @Value("${consume.desc}") private String consumeDesc; @Value("#{'${api.server.round.card}'.split(',')}") private List<String> cardList; }
Question:
Is this issue related with lifecycle of SpEL? It seems that, the value of SpEL is not yet parsed.
1 Answers
Answers 1
The split should return an array of String, not a list. Try this:
@Value("#{'${api.server.round.card}'.split(',')}") private String[] cardList;
0 comments:
Post a Comment