Я получаю javax.servlet.ServletException: Servlet execution threw an exception
, когда развертываю свой .war на Apache Tomcat
.
Исключение
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Причина
java.lang.ExceptionInInitializerError
java.base/java.lang.Class.forName0(Native Method)
java.base/java.lang.Class.forName(Class.java:398)
org.zkoss.lang.Classes.forNameByThread(Classes.java:274)
org.zkoss.lang.ImportedClassResolver.resolveClass(ImportedClassResolver.java:129)
org.zkoss.zk.ui.impl.PageImpl.resolveClass(PageImpl.java:575)
org.zkoss.zk.ui.impl.AbstractUiFactory.newComposer(AbstractUiFactory.java:184)
org.zkoss.zk.ui.impl.Utils.newComposer(Utils.java:91)
org.zkoss.zk.ui.metainfo.ComponentInfo.toComposer(ComponentInfo.java:360)
org.zkoss.zk.ui.metainfo.ComponentInfo.toComposers(ComponentInfo.java:330)
org.zkoss.zk.ui.metainfo.ComponentInfo.resolveComposer(ComponentInfo.java:318)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:901)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:894)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:781)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:841)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:799)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:745)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:466)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:374)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:215)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:140)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Причина
java.lang.NullPointerException
java.base/java.util.Objects.requireNonNull(Objects.java:221)
java.logging/java.util.logging.Logger.addHandler(Logger.java:2060)
xx.xx.xx.util.ApplicationLogger.log(ApplicationLogger.java:118)
xx.xx.xx.composers.LoginComposer.<clinit>(LoginComposer.java:115)
java.base/java.lang.Class.forName0(Native Method)
java.base/java.lang.Class.forName(Class.java:398)
org.zkoss.lang.Classes.forNameByThread(Classes.java:274)
org.zkoss.lang.ImportedClassResolver.resolveClass(ImportedClassResolver.java:129)
org.zkoss.zk.ui.impl.PageImpl.resolveClass(PageImpl.java:575)
org.zkoss.zk.ui.impl.AbstractUiFactory.newComposer(AbstractUiFactory.java:184)
org.zkoss.zk.ui.impl.Utils.newComposer(Utils.java:91)
org.zkoss.zk.ui.metainfo.ComponentInfo.toComposer(ComponentInfo.java:360)
org.zkoss.zk.ui.metainfo.ComponentInfo.toComposers(ComponentInfo.java:330)
org.zkoss.zk.ui.metainfo.ComponentInfo.resolveComposer(ComponentInfo.java:318)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:901)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:894)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:781)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:841)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:799)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:745)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:466)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:374)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:215)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:140)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Это то, что у меня в строке 118 на ApplicationLogger.java
logger.addHandler(fileHandler);
И это то, что у меня в строке 115 на LoginComposer.java
ApplicationLogger.log(Level.INFO, PROPERTIES.getProperty("LOG_HEADER"),className);
ApplicationLogger. java
public class ApplicationLogger {
private static ApplicationLogger applicationLogger;
private static Logger logger;
private static final SimpleFormatter simpleFormatter = new SimpleFormatter();
private static final Properties PROPERTIES = new Properties();
private static final String PROPERTIES_FILE = "application-masterconfig.properties";
private static FileHandler fileHandler;
private ApplicationLogger() {
}
static {
try {
// Get context ClassLoader for this thread.
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// InputStream for reading the properties file.
InputStream inputStream = classLoader.getResourceAsStream(PROPERTIES_FILE);
// Read the property list
PROPERTIES.load(inputStream);
// Initialize the file handler. true ensures append mode.
fileHandler = new FileHandler(PROPERTIES.getProperty("PATH_TO_APPLICATION_LOGS_DEVELOPMENT"), true);
// This Formatter will be used to format LogRecords for this Handler.
fileHandler.setFormatter(simpleFormatter);
} catch(SecurityException securityException) {
securityException.printStackTrace();
} catch(IOException ioException) {
ioException.printStackTrace();
} finally {
}
}
public static ApplicationLogger getNewInstance() {
if (Objects.isNull(applicationLogger)) {
return new ApplicationLogger();
}
return applicationLogger;
}
public static void log(final Level level, final String msg, final String canonicalClassName) {
logger = Logger.getLogger(canonicalClassName);
logger.addHandler(fileHandler);
logger.setUseParentHandlers(false); // No need to write at console.
logger.log(level, msg); // Log the message
}
}
Login Composer. java
public class LoginComposer extends GenericForwardComposer < Component > {
...
...
...
...
static {
try {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(PROPERTIES_FILE);
PROPERTIES.load(inputStream);
/**
* <p>
* Log the message indicating the appication has started and the login page has
* loaded.
*/
ApplicationLogger.log(Level.INFO, PROPERTIES.getProperty("LOG_HEADER"), className);
} catch(SecurityException securityException) {
ApplicationLogger.log(Level.INFO, PROPERTIES.getProperty("SECURITY_VIOLATION_EXCEPTION_HEADER"), className);
PRINT_WRITER = new PrintWriter(STRING_WRITER);
securityException.printStackTrace(PRINT_WRITER);
ApplicationLogger.log(Level.SEVERE, STRING_WRITER.toString(), className);
} catch(IOException ioException) {
ApplicationLogger.log(Level.INFO, PROPERTIES.getProperty("IOEXCEPTION_HEADER"), className);
PRINT_WRITER = new PrintWriter(STRING_WRITER);
ioException.printStackTrace(PRINT_WRITER);
ApplicationLogger.log(Level.SEVERE, STRING_WRITER.toString(), className);
}
}
......
}
Как исправить, пожалуйста? Любая помощь приветствуется.