我如何使用SLF4J在GlassFish 3上使用Hibernate JPA部署Java EE Web应用程序? [英] How can I use SLF4J for my Java EE web application deployed on GlassFish 3 with Hibernate JPA?

查看:103
本文介绍了我如何使用SLF4J在GlassFish 3上使用Hibernate JPA部署Java EE Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在特定的GlassFish应用程序中使用SLF4J,并仅为该应用程序配置SLF4J?我们目前正在苦苦思索GlassFish本身安装了Hibernate的GlassFish包含了SLF4J API和一个在其lib目录中的记录器绑定。



我们的团队正在开发一个Java EE 6 Web应用程序。对于开发,应用程序部署在GlassFish 3.1.2上,它应该尽可能便携。



我们决定使用SLF4J来记录应用程序消息。根据消息级别,应用程序必须以不同方式处理某些日志消息,因此必须能够自行配置日志记录后端 - 而不是在应用程序服务器中配置日志记录。



不幸的是,GlassFish 3.1.2在它的lib文件夹中包含了 slf4j-api-1.5.8.jar slf4j-jdk14-1.5.8.jar 。这会阻止我们的应用程序使用 slf4j-api-1.7.5.jar slf4j-simple-1.7.5.jar <后者将被另一个绑定最终替换) 。

有没有什么办法可以告诉GlassFish在考虑自己的应用程序库(以便使用正确版本的API)之前考虑应用程序库,并且有任何方法可以确保应用程序提供了SLF4J绑定吗?



我们正在使用Eclipse进行开发,但我们未使用Maven 。到目前为止,我发现的大多数调整/解决方法都是指Maven中的配置,我们不能使用它。如果你可以提供任何Eclipse特定的技巧,那将是很棒的。在Eclipse项目的属性中,我已经配置了构建路径的顺序,以便Web App库处于顶层。但不知何故,这似乎还不够。



非常感谢您的帮助!



更新1:为了让它暂时工作,我只是从GlassFish lib目录中删除了SLF4J库。应用程序然后使用它自己提供的SLF4J库。但我不认为这是部署过程的解决方案,我不确定这是否会破坏GlassFish所使用的任何内容(为什么库会驻留在那里?),这对我们的开发团队来说不是一个实用的解决方案。

更新2 :实际上它不是
GlassFish,其中包括干扰SLF4J库开箱即用但通过更新工具安装的 Hibernate JPA 包。我们目前不需要Hibernate JPA,但是在某些时候需要更改为Hibernate,我们还希望通过安装Hibernate JPA或其他包含SLF4J的软件包,让应用程序轻松移植到应用程序服务器。我相应地更新了问题标题。 如何解决应用程序服务器和应用程序的干扰依赖关系的一般问题?

解决方案

由于类加载器委派,请尝试对其进行更改,以便将应用程序中的类从父类的类中取出。


Is it possible to use SLF4J in a specific GlassFish application and configure SLF4J solely for that application? We are currently struggling with the fact that GlassFish itself GlassFish with Hibernate installed contains the SLF4J API and a logger binding in its lib directory.

Our team is developing a Java EE 6 web application. For development the application is deployed on GlassFish 3.1.2, it should be as portable as possible though.

We decided to use SLF4J to log application messages. Depending on the message level the application has to handle certain log messages differently and thus must be able to configure the logging backend on its own -- as opposed to configuring logging in the application server.

Unfortunately GlassFish 3.1.2 includes slf4j-api-1.5.8.jar and slf4j-jdk14-1.5.8.jar in its lib folder. This prevents our application from using slf4j-api-1.7.5.jar and slf4j-simple-1.7.5.jar (the latter will be replaced by another binding eventually).

Is there any way to tell GlassFish to consider the application lib's before considering its own (so that the correct version of the API is used) and any way to make sure that the application provided SLF4J binding is used?

We are using Eclipse for development but we are not using Maven. Most tweaks/workarounds I found so far refer to configuration in Maven which we cannot use. If you can provide any Eclipse specific tips, that would be great though. In the Eclipse project's properties I already configured the order of the build path so that the Web App Libraries are on top. But somehow this doesn't seem to be enough.

Many thanks for your help!

Update 1: To get it working temporarily I just removed the SLF4J libraries from the GlassFish lib directory. The application then uses its self provided SLF4J libraries. But I don't consider this a solution for the deployment process, I'm not sure if this might break anything used by GlassFish (why would the libraries reside there anyway?), and this is not a practical solution for our development team.

Update 2: Actually it is not GlassFish which includes the interfering SLF4J library out-of-the-box but the Hibernate JPA package I installed via the Update Tool. We currently do not need Hibernate JPA but the requirement to change to Hibernate might arise at some point and we'd also like to keep the application easily portable to application servers with Hibernate JPA or other SLF4J-containing packages installed. I updated the question title accordingly. How can this general issue of interfering dependencies of application server and application be solved?

解决方案

This is due to the 'Class Loader Delegation', try to change it so that it takes the classes from your application over the classes from the parent.

这篇关于我如何使用SLF4J在GlassFish 3上使用Hibernate JPA部署Java EE Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆