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

Sim*_*ant 9 java spring hibernate spring-boot hibernate-types

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

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                  : 
 _    _                           _     _
| |  | |                         (_)   | |
| |__| |_   _ _ __   ___ _ __ ___ _ ___| |_ ___ _ __   ___ ___
|  __  | | | | '_ \ / _ \ '__/ __| / __| __/ _ \ '_ \ / __/ _ \
| |  | | |_| | |_) |  __/ |  \__ \ \__ \ ||  __/ | | | (_|  __/
|_|  |_|\__, | .__/ \___|_|  |___/_|___/\__\___|_| |_|\___\___|
         __/ | |
        |___/|_|

           ____        _   _           _
          / __ \      | | (_)         (_)
         | |  | |_ __ | |_ _ _ __ ___  _ _______ _ __
         | |  | | '_ \| __| | '_ ` _ \| |_  / _ \ '__|
         | |__| | |_) | |_| | | | | | | |/ /  __/ |
          \____/| .__/ \__|_|_| |_| |_|_/___\___|_|
                | |
                |_|
Run Code Online (Sandbox Code Playgroud)

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

Sim*_*ant 6

项目所有者描述了为什么引入横幅,为什么默认情况下不会禁用它以及如何手动禁用它。

如何移除 Hibernate Types 横幅

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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.

  • @VladMihalcea,即使我使用的是 hibernate-types-55:2.12.0,我也无法通过 spring.jpa.properties.hibernate.types.print.banner=false 关闭横幅。知道为什么吗?(我可以通过创建 hibernate.properties 文件将其关闭) (2认同)

Jod*_*iug 5

如果您无权访问 JVM 参数,则可以替代上述答案。

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

选项 1:附加属性文件

src/main/resources/hibernate-types.properties.

hibernate.types.print.banner=false
Run Code Online (Sandbox Code Playgroud)

选项 2:绕过休眠类型检查

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

最新的做事方式:src/main/java/io/hypersistence/optimizer/core/License.java.

package io.hypersistence.optimizer.core;

public class License {
  public static class Signature {
  }
}
Run Code Online (Sandbox Code Playgroud)

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

package io.hypersistence.optimizer;

public class HypersistenceOptimizer {
}
Run Code Online (Sandbox Code Playgroud)