如标题所示,错误张贴在下面。我还试图将AppPropertyDir放在我的环境变量中,但这只会帮助解决其他的注入问题,而不是这个问题!
@Configuration("appPropertiesLoader")
public class AppPropertiesLoader {
// I ommitted other unnecessary code, this is where it fails at injecting
@Value("#{systemProperties.AppPropertyDir}")
private String appPropertyDir;
}<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
metadata-complete="true" id="WebApp_ID" version="2.5">
<!-- change below params according to local setup -->
<context-param>
<param-name>AppPropertyDir</param-name>
<param-value>C:\Users\properties-location</param-value>
</context-param>
</web-app>误差
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'AppPropertyDir' cannot be found on object of type 'java.util.Properties' - maybe not public or not valid?发布于 2019-07-25 20:30:56
问题是这样的!@Value("#{systemProperties.AppPropertyDir}")必须在系统运行上运行(所以在其他事情之前)!因此,需要在测试类的包中的任何地方运行@postConstruct。在您的postConstruct方法中,只需确保将AppPropertyDir初始化为C:\Users\properties-location
@PostConstruct
public void init() {
System.setProperty("AppPropertyDir", "C:\Users\properties-location");
}https://stackoverflow.com/questions/57208365
复制相似问题