如何在使用Spring Boot时禁用hibernate-types-52时的Hypersistence横幅?

huangapple go评论88阅读模式
英文:

How to disable the Hypersistence banner when using hibernate-types-52 in Spring Boot?

问题

我在我的Spring Boot项目中使用了com.vladmihalcea:hibernate-types-52依赖项。并且我注意到在应用程序启动时,添加了一些大的日志消息:

2020-04-09 11:43:59.535  WARN 3465 --- [           main] Hypersistence Optimizer                  : 您应该使用Hypersistence Optimizer来加速您的Hibernate应用程序!
2020-04-09 11:43:59.535  WARN 3465 --- [           main] Hypersistence Optimizer                  : 更多详情,请访问https://vladmihalcea.com/hypersistence-optimizer/
2020-04-09 11:43:59.536  INFO 3465 --- [           main] Hypersistence Optimizer                  : 
 _    _                           _     _
| |  | |                         (_)   | |
| |__| |_   _ _ __   ___ _ __ ___ _ ___| |_ ___ _ __   ___ ___
|  __  | | | | ' _ \ / _ ' __/ __| / __| __/ _ ' _ \ / __/ _ \
| |  | | |_| | |_) |  __/ |  \__ \ \__ \ ||  __/ | | | (_|  __/
|_|  |_|\__, | .__/ \___|_|  |___/_|___/\__\___|_| |_|\___\___|
         __/ | |
        |___/|_|
    
           ____        _   _           _
          / __ \      | | (_)         (_)
         | |  | |_ __ | |_ _ _ __ ___  _ _______ _ __
         | |  | | ' _ \| __| | ' _ ` _ \| |_  / _ ' __|
         | |__| | |_) | |_| | | | | | | |/ /  __/ |
          \____/| .__/ \__|_|_| |_| |_|\_/___\___|_|
                | |
                |_|

这个提示很好,项目听起来确实有趣,但我仍然希望从我的应用程序中移除这个横幅。

英文:

I use the com.vladmihalcea:hibernate-types-52 dependency in my Spring Boot Project. And, I notice that on application boot, some large log messages were added:

2020-04-09 11:43:59.535  WARN 3465 --- [           main] Hypersistence Optimizer                  : You should use Hypersistence Optimizer to speed up your Hibernate application!
2020-04-09 11:43:59.535  WARN 3465 --- [           main] Hypersistence Optimizer                  : For more details, go to https://vladmihalcea.com/hypersistence-optimizer/
2020-04-09 11:43:59.536  INFO 3465 --- [           main] Hypersistence Optimizer                  : 
 _    _                           _     _
| |  | |                         (_)   | |
| |__| |_   _ _ __   ___ _ __ ___ _ ___| |_ ___ _ __   ___ ___
|  __  | | | | '_ \ / _ \ '__/ __| / __| __/ _ \ '_ \ / __/ _ \
| |  | | |_| | |_) |  __/ |  \__ \ \__ \ ||  __/ | | | (_|  __/
|_|  |_|\__, | .__/ \___|_|  |___/_|___/\__\___|_| |_|\___\___|
         __/ | |
        |___/|_|

           ____        _   _           _
          / __ \      | | (_)         (_)
         | |  | |_ __ | |_ _ _ __ ___  _ _______ _ __
         | |  | | '_ \| __| | '_ ` _ \| |_  / _ \ '__|
         | |__| | |_) | |_| | | | | | | |/ /  __/ |
          \____/| .__/ \__|_|_| |_| |_|_/___\___|_|
                | |
                |_|

The hint is nice and the project sounds actually interesting, but still want to have the banner removed from my application.

答案1

得分: 21

以下是翻译好的内容:

项目所有者解释了引入横幅的原因,为什么默认情况下不能禁用它,以及如何手动禁用它。

如何移除 Hibernate Types 横幅

自动移除横幅模式

简而言之,您可以购买Hypersistence Optimizer 许可证,并将该项目添加为依赖项,以从 JPA 和 Hibernate 自动调整检查中受益。

手动移除横幅

或者,您可以将 hibernate.propertieshibernate-types.properties 文件添加到您的项目中,并添加以下属性以禁用横幅:

hibernate.types.print.banner = false

或者,您可以将此属性作为 Java 系统属性传递:

java -Dhibernate.types.print.banner=false -jar target/high-performance-java-persistence-1.0.0.jar

Spring Boot

从 Hibernate 5.5 版本和 hibernate-types-55 依赖项发布开始,您现在可以在 application.properties 文件中提供 hibernate.types.print.banner 属性,如下所示:

spring.jpa.properties.hibernate.types.print.banner=false

> 如果您正在使用 hibernate-types-52 或更旧的依赖项,则无法通过 Spring Boot 的 application.properties 文件提供此设置。

英文:

There is a description by the Project Owner why the banner was introduced, why it will not be disabled on default and how to disable it manually.

How to remove the Hibernate Types banner

The automatic banner removal mode

In short, you can buy a Hypersistence Optimizer license and add the project as a dependency to benefit from the JPA and Hibernate auto-tuning checks.

Manual banner removal

Or you can add either a hibernate.properties or hibernate-types.properties file to your project with the one property to disable the banner:

hibernate.types.print.banner = false

Or, you could pass this property as a Java System property:

java -Dhibernate.types.print.banner=false -jar target/high-performance-java-persistence-1.0.0.jar

Spring Boot

Starting with the release of Hibernate 5.5 and the hibernate-types-55 dependency, you can now provide the hibernate.types.print.banner property in your application.properties file, like this:

spring.jpa.properties.hibernate.types.print.banner=false

> If you're using hibernate-types-52 or older dependencies, then you won't be able to provide this setting via the Spring Boot application.properties file.

答案2

得分: 9

除了上面的答案之外的另一种选择,如果您无法访问JVM参数。

这两种方法都适用于Spring Boot,在2.2.x版本上进行了测试。

选项1:额外的属性文件

src/main/resources/hibernate-types.properties创建一个文件。

hibernate.types.print.banner=false

选项2:绕过hibernate-types检查的方法

创建以下文件之一(取决于您的hibernate-types版本)。

最新的做法:src/main/java/io/hypersistence/optimizer/core/License.java

package io.hypersistence.optimizer.core;

public class License {
  public static class Signature {
  }
}

较旧版本检查src/main/java/io/hypersistence/optimizer/HypersistenceOptimizer.java

package io.hypersistence.optimizer;

public class HypersistenceOptimizer {
}
英文:

An alternative to the answers above, if you do not have access to JVM arguments.

Both these approaches work with Spring Boot, tested on 2.2.x.

Option 1: additional properties file

Create a file at src/main/resources/hibernate-types.properties.

hibernate.types.print.banner=false

Option 2: hacking around the hibernate-types check

Create either of the following files (depending on your version of hibernate-types).

Latest way of doing things: src/main/java/io/hypersistence/optimizer/core/License.java.

package io.hypersistence.optimizer.core;

public class License {
  public static class Signature {
  }
}

An older version checks for src/main/java/io/hypersistence/optimizer/HypersistenceOptimizer.java.

package io.hypersistence.optimizer;

public class HypersistenceOptimizer {
}

答案3

得分: 0

只需在日志配置文件中包含记录器名称和日志级别设置为 WARNERROR

log4j2 (log4j2.yml) 为例:

configuration:
  Loggers:
    Logger:
      - name: Hibernate Types
        level: WARN

注意:这里的记录器名称很重要:Hibernate Types。已测试适用于 hibernate-types-52:2.9.13。对于其他版本也可以实现相同效果,只需包含适当的记录器名称。可以在日志中找到记录器名称。

英文:

Just include the logger name and the level to WARN or ERROR in the log configuration file.

Example for log4j2 (log4j2.yml):

configuration:
  Loggers:
    Logger:
      - name: Hibernate Types
        level: WARN

Note: Logger's name is important here: Hibernate Types. Tested for hibernate-types-52:2.9.13. The same can be achieved for other versions, just include the proper logger name. One can find the logger name in the logs.

如何在使用Spring Boot时禁用hibernate-types-52时的Hypersistence横幅?

huangapple
  • 本文由 发表于 2020年4月9日 17:53:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/61118423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定