我有一个属性文件 myprops.properties,如下所示:
Wsdl=someurl
UserName=user
UserPassword=pasword
Application=appName
在我的 Controller 中,我正尝试访问我的服务中的设置值,如下所示
Properties prop = new Properties();
prop.load(new FileInputStream("resources/myprops.properties"));
myService.setWsdl(prop.getProperty("Wsdl"));
myService.setUserName(prop.getProperty("UserName"));
myService.setUserPassword(prop.getProperty("UserPassword"));
myService.setApplication(prop.getProperty("Application"));
我的问题是我只是不知道要使用什么路径。如果这有什么不同的话,它是一个 Spring 项目。理想情况下,我希望将属性文件放在我的“src/main/resources”文件夹中
我意识到这对某些人来说可能非常简单,但我已经尝试在此处和 Google 上搜索解决方案,但我似乎无法找到有帮助的解决方案。我试过在项目中移动文件,但似乎无法弄清楚
我得到的错误是
java.io.FileNotFoundException: resources\drm.properties (The system cannot find the path specified)
任何建议/解释甚至清楚解释它的链接都很棒
最佳答案
好吧,src/main/resources 在类路径上,你只需要这样做。
Properties properties = PropertiesLoaderUtils.loadAllProperties("你的属性文件名");
关于java - 我如何或在哪里访问我的属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15071158/