在其他示例中,我尝试过在 WebLogic Admin Server 11g 上未找到 DeploymentException 和类,但我无法让 Spring 读取外部属性文件。
我有这段代码,它读取一个属性文件。将文件(PROPERTIES_FILES)放在 src/main/resources 中,我部署的应用程序很好。将其移动到文件系统中的外部文件夹,无法部署。
我尝试http://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/来打印类路径并获得:
/C:/Oracle/Middleware/patch_wls1034/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/C:/Oracle/Middleware/patch_oepe1040/profiles/default/sys_manifest_classpath/weblogic_patch.jar /C:/Oracle/Middleware/patch_ocp360/profiles/default/sys_manifest_classpath/weblogic_patch.jar
/C:/Oracle/Middleware/jdk160_21/lib/tools.jar
/C:/Oracle/Middleware/wlserver_10.3/server/lib/weblogic_sp.jar
/C:/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar
/C:/Oracle/Middleware/modules/features/weblogic.server.modules_10.3.4.0.jar
/C:/Oracle/Middleware/wlserver_10.3/server/lib/webservices.jar
/C:/Oracle/Middleware/modules/org.apache.ant_1.7.1/lib/ant-all.jar
/C:/Oracle/Middleware/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar
/C:/Oracle/Middleware/wlserver_10.3/common/derby/lib/derbyclient.jar
/C:/Oracle/Middleware/wlserver_10.3/server/lib/xqrl.jar
Trying to read test.properties
Found false
Could not find properties file: test.properties
我的实现如下所示:
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url: urls){
logger.debug(url.getFile());
}
logger.debug("Trying to read {}", PROPERTIES_FILES);
Resource resource = new ClassPathResource(PROPERTIES_FILES);
logger.debug("Found {}", resource.exists());
try {
props = PropertiesLoaderUtils.loadProperties(resource);
} catch (IOException e) {
logger.error("Could not find properties file: " + PROPERTIES_FILES, e);
}
我从 servlet-dispatcher 中移动另一个属性文件时遇到同样的问题:
<context:property-placeholder location="classpath*:test.properties"/>
但我想这是同样的问题。我在 Windows 上。
有谁能够帮我?