gpt4 book ai didi

java - @Value ("#{systemProperties.AppPropertyDir}")找不到AppPropertyDir

转载 作者:行者123 更新时间:2023-12-02 02:35:03 25 4
gpt4 key购买 nike

正如标题所示,下面发布了错误。我还尝试将 AppPropertyDir 放入我的环境变量中,但这只能帮助解决其他注入(inject)问题,但对这个问题没有帮助!

@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?

最佳答案

问题是这样的!@Value("#{systemProperties.AppPropertyDir}") 必须在系统运行时运行(所以在其他所有事情之前)!因此,需要有一个 @postConstruct 来从测试类包中的任何位置运行。在 postConstruct 方法中,只需确保将 AppPropertyDir 初始化为 C:\Users\properties-location

@PostConstruct 
public void init() {
System.setProperty("AppPropertyDir", "C:\Users\properties-location");
}

关于java - @Value ("#{systemProperties.AppPropertyDir}")找不到AppPropertyDir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57208365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com