Derby 有一系列由系统属性控制的配置选项。在 webapp 中安排系统属性设置是相当痛苦的。有没有人提出解决方案?
此外,我一直无法让它们在 web 应用程序中工作。
这是 servlet 上下文侦听器的代码。derby.log 仍然在容器的 cwd 中创建,而不是对我的日志记录过程进行调用。
/**
* Listener to try to get Derby to behave better.
*/
public class ContextListener implements ServletContextListener {
private static final String TEMP_DIR_ATTRIBUTE = "javax.servlet.context.tempdir";
private static ServletContext context;
private static Writer logWriter;
private class LogWriter extends Writer {
@Override
public void close() throws IOException {
}
@Override
public void flush() throws IOException {
}
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
context.log(new String(cbuf, off, len));
}
}
/** {@inheritDoc}*/
public void contextDestroyed(ServletContextEvent sce) {
}
public static Writer getLogSteam() {
return logWriter;
}
/** {@inheritDoc}*/
public void contextInitialized(ServletContextEvent sce) {
logWriter = new LogWriter();
File tempDirFile = (File)sce.getServletContext().getAttribute(TEMP_DIR_ATTRIBUTE);
context = sce.getServletContext();
System.setProperty("derby.system.home", tempDirFile.getAbsolutePath());
System.setProperty("derby.stream.error.method", "com.basistech.vws.ContextListener.getLogStream");
}
}