添加SSL配置后,log4j无法与Jetty一起使用

时间:2014-05-05 22:25:36

标签: java ssl https log4j jetty

我正在尝试使用SSL运行Jetty(v9)服务器(因此只能通过HTTPS访问)。使用普通HTTP,一切运行正常。然后我改变了我的启动器类,看起来像这样:

PropertyConfigurator.configure("war/WEB-INF/log4j.properties");
Server server = new Server();

WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("war");
server.setHandler(webapp);

HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());

SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("keystore.jks");
sslContextFactory.setKeyStorePassword("<password>");
sslContextFactory.setKeyManagerPassword("<password>");

ServerConnector sslConnector = new ServerConnector(server,
        new SslConnectionFactory(sslContextFactory, "http/1.1"),
        new HttpConnectionFactory(https));
sslConnector.setPort(443);
server.setConnectors(new Connector[] { sslConnector });

LOG.info("Starting server on port 443");
server.start();
server.join();

我也运行它来生成密钥库文件:

keytool -genkey -alias sitename -keyalg RSA -keystore keystore.jks -keysize 2048

当我现在启动服务器时,一切都很好。我使用log4j(v1.2.17 - 和slf4j)的日志记录输出到目标文件(如我的log4j.properties中所示),并带有上述日志消息。但是当我在浏览器中点击Web服务器时,日志记录将停止使用以下错误输出到控制台:

log4j:ERROR A "org.apache.log4j.RollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [sun.misc.Launcher$AppClassLoader@178b0f9] whereas object of type 
log4j:ERROR "org.apache.log4j.RollingFileAppender" was loaded by [WebAppClassLoader=8317419@7ee9eb].
log4j:ERROR Could not instantiate appender named "filer".
log4j:WARN No appenders could be found for logger (ie.search4less.quickbooks.servlet.AppServlet).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

...每次servlet处理新请求时,都会向控制台重复此操作。我的每个servlet都使用静态块初始化log4j,如:

static {
    PropertyConfigurator.configure("war/WEB-INF/log4j.properties");
}

我的log4j.properties看起来像这样:

log4j.rootLogger=INFO, filer

log4j.appender.filer=org.apache.log4j.RollingFileAppender
log4j.appender.filer.layout=org.apache.log4j.PatternLayout
log4j.appender.filer.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4r [%t] %-5p %c %x - %m%n
log4j.appender.filer.File=./logs/quickbooks.log
log4j.appender.filer.MaxFileSize=1MB
log4j.appender.filer.MaxBackupIndex=9
log4j.appender.filer.append=true

正如我所说,一切正常,直到我将新的SSL配置代码添加到服务器启动器类,但我不明白出了什么问题。

1 个答案:

答案 0 :(得分:0)

我得到了它的工作。问题实际上与SSL配置无关。在添加这些SSL配置更改之间,我已将lib目录移动到包含所有依赖项(包括log4j和slf4j jar)的WEB-INF中。这引起了某种冲突。从那里删除它解决了它。