我有 application.properties 文件,我成功地使用 @Value 从中获取了字符串值。我在从中获取 int 时遇到问题。
jedisHostName=127.0.0.1
redisPort=6379
在我的配置类中,我有
@Value("${jedisHostName}")
private String hostName;
它工作正常,但是当我尝试
@Value("#{new Integer.parseInt('${redisPort}')}")
private Integer redisPort;
我得到
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'secret***': Unsatisfied dependency expressed through field 'redisPort';
我也只尝试
@Value("#{new Integer('${redisPort}')}")
但我得到同样的例外。我什至试图简单地做一个
@Value("${redisPort}")
private String redisPort;
int jedisPort = Integer.parseInt(redisPort.trim());
但后来我得到
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'secret***' defined in file [secret***.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate **** Constructor threw exception; nested exception is java.lang.NullPointerException
我有普通的类名,但我使用“secret***”作为例子
一只斗牛犬
相关分类