运行时依赖项(例如连接池)和类路径? [英] Runtime dependency (e.g. connection pooling) and classpath?

查看:291
本文介绍了运行时依赖项(例如连接池)和类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Hibernate 3的Maven 3项目。在Hibernate属性文件中,有一个hibernate.connection.provider_class条目,其类别对应于C3P0连接提供程序(org.hibernate.connection.C3P0ConnectionProvider)。显然,该类仅在运行时使用,因此我不需要在带有编译范围的POM中添加相应的依赖项。现在,我想提供使用所需的任何连接池框架的可能性,所以我也不要在POM中添加运行时依赖项

I have a Maven 3 project that uses Hibernate 3. In the Hibernate properties file, there is an entry for hibernate.connection.provider_class with the class corresponding to the C3P0 connection provider (org.hibernate.connection.C3P0ConnectionProvider). Obviously, this class is only used at runtime, so I don't need to add the corresponding dependency in my POM with the compile scope. Now, I want to give the possibility to use any connection pooling framework desired, so I also don't add a runtime dependency to the POM.

最佳实践是什么?

我考虑过在应用程序处于运行状态时将一个条目添加到与运行时依赖项相对应的类路径(在本例中为hibernate-c3p0)。运行(例如,使用命令行)。但是,我不知道是否可能。

I thought about adding an entry to the classpath corresponding to the runtime dependency (in this case, hibernate-c3p0) when the application is run (for example, using the command line). But, I don't know if it's possible.

这几乎(也许是完全)与SLF4J相同的问题。我不知道Hibernate是否也使用外观模式进行连接池。

This is almost (maybe exactly) the same problem as with SLF4J. I don't know if Hibernate also uses the facade pattern for connection pooling.

谢谢

推荐答案

由于您的代码不依赖于连接池(无论是主代码还是测试都不需要),因此在任何地方都没有必要提及依赖。

Since your code doesn't depend on the connection pooling (neither the main code nor the tests need it), there is no point to mention the dependency anywhere.

如果有人应该提到它,那将是Hibernate,因为Hibernate在其配置中提供了此功能。

If anyone should mention it, then that would be Hibernate because Hibernate offers this feature in its config.

但是您可以使用可选:true 表示:


  1. 我支持此功能

  2. 如果您使用它,那么我建议使用此框架和此版本

这将使消费者的生活变得更加简单

That will make life slightly more simple for consumers of your project.

但是总的来说,除非其他项目对您的代码有影响,否则您不应提及其他项目提供/需要的功能(例如当您提供更简单的方法时)为Hibernate配置连接池)。

But overall, you should not mention features provided/needed by other projects unless they have some impact on your code (like when you offer a more simple way to configure connection pooling for Hibernate).

您可能主要关心的是如何配置项目以进行质量检查。此新动作的技术术语是 DevOps -而不是产生客户产生的转储WAR (QA)必须进行艰苦的配置,就像其他所有配置一样,配置是开发过程的一部分。您传递的是一个已完全配置且可以运行的设置。

Your main concern is probably how to configure the project for QA. The technical term for this new movement is "DevOps" - instead of producing a dump WAR which the customer (QA) has to configure painstakingly, configuration is part of the development process just like everything else. What you pass on is a completely configured, ready-to-run setup.

要实现此目的,请创建另一个名为 project - qa,这取决于您的项目以及将无效代码转换为正在运行的应用程序所需的所有其他操作(因此,它将取决于DBCP加上所有必需的配置文件)。

To implement this, create another Maven module called "project-qa" which depends on your project and everything else you need to turn the dead code into a running application (so it will depend on DBCP plus it will contain all the necessary config files).

Maven支持叠加的WAR ,这将使您能够轻松实现这一目标。

Maven supports overlayed WARs which will allow you to implement this painlessly.

这篇关于运行时依赖项(例如连接池)和类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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