是否可以使用Spring @Value来将属性文件中的值映射到HashMap中。
目前我有这样的代码,将一个值映射是没有问题的。 但我需要将自定义的值映射到HashMap的过期时间中。 这种情况是否可能?
@Service
@PropertySource(value = "classpath:my_service.properties")
public class SomeServiceImpl implements SomeService {
@Value("#{conf['service.cache']}")
private final boolean useCache = false;
@Value("#{conf['service.expiration.[<custom name>]']}")
private final HashMap<String, String> expirations = new HashMap<String, String>();
属性文件:'my_service.properties'
service.cache=true
service.expiration.name1=100
service.expiration.name2=20
能否像这样映射键值对:
name1 = 100
name2 = 20