我們最近必須從頭開始設置一個tomcat服務器。 Tomcat版本是8.0.20。部署一個war文件,現在System.getProperty("mode")
返回「null」,它應該返回PREPROD。System.getProperty(「mode」)返回「null」
它應該從位於webapps目錄中的mode.properties文件讀取此「模式」。這兩行註釋掉了另一部分代碼,這些代碼在新的tomcat服務器上不再有效。我用應該工作的代碼替換它。
//String pathOfWebInf = sce.getServletContext().getRealPath("WEB-INF");
//String pathOfLocalhostFile = pathOfWebInf + File.separator + "classes"
// + File.separator;
String pathOfLocalhostFile = this.getClass().getResource("/").getPath();
String mode = System.getProperty("mode");
String fileName = "localhost-oracle.properties." + mode;
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("xxx");
Properties dbProps = new EncryptableProperties(encryptor);
try
{
InputStream is = new FileInputStream(pathOfLocalhostFile + fileName);
dbProps.load(is);
} catch (Exception e)
{
throw new IOException("Could not read properties file " + pathOfLocalhostFile + fileName);
}
我建議把你的屬性變成catalina.properties在服務器/ conf文件夾。 –
我解決了問題,通過恢復到Tomcat 7,Tomcat 8有問題,如http://stackoverflow.com/questions/32197494/why-does-servletcontext-getrealpath-returns-null-on-tomcat-8 – Adder