Java spring.datasource.initialization-mode 的可能值是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53922279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:55:57  来源:igfitidea点击:

What are the possible values of spring.datasource.initialization-mode?

javaspringspring-boot

提问by Christine

I am configuring a database in Spring JPA and I want to know what the possible values are of spring.datasource.initialization-mode. I found this pagewith common properties but it doesn't give all possible vallues. I'd expect there to be some documentation on all possible values of all properties you can set.

我正在 Spring JPA 中配置一个数据库,我想知道spring.datasource.initialization-mode. 我发现这个页面具有共同的属性,但它没有给出所有可能的值。我希望有一些关于您可以设置的所有属性的所有可能值的文档。

I am using the property in the props section in my applicationContext.xmlas properties for the entityManagerFactory

我正在使用我的道具部分中的applicationContext.xml属性作为属性entityManagerFactory

<util:properties id="props">
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    <prop key="hibernate.ddl-auto">create</prop>
    <prop key="spring.jpa.show-sql">true</prop>
    <prop key="spring.jpa.generate.ddl">true</prop>
    <prop key="spring.jpa.hibernate.ddl-auto">create</prop>
    <prop key="spring.datasource.initialization-mode">always</prop>
    <prop key="spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation">true</prop>
</util:properties>

回答by Christine

When all else fails, you remember "use the source, Luke!". The values are given in the Javadocof the enum DataSourceInitializationMode. Values are always, embeddedand never.

当所有其他方法都失败时,你记得“使用源,卢克!”。这些值在 enum的Javadoc中给出DataSourceInitializationMode。值为alwaysembeddednever

回答by The Nested Programmer

Forgive me for butting in almost a year late. After having faced a similar problem as explained by Christine, I decided to take the clue and begin searching in the source. It would appear that the following is detailed in the link here https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/jdbc/DataSourceInitializationMode.html:

原谅我迟到了将近一年。在遇到了由 解释的类似问题后Christine,我决定抓住线索并开始在source. 似乎在https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/jdbc/DataSourceInitializationMode.html的链接中详细说明了以下内容:

Enum Constant Summary Enum Constants

Enum Constant and Description

ALWAYSAlways initialize the datasource.

EMBEDDEDOnly initialize an embedded datasource.

NEVERDo not initialize the datasource.

枚举常量摘要 枚举常量

枚举常量和描述

ALWAYS始终初始化数据源。

EMBEDDED仅初始化嵌入的数据源。

NEVER不要初始化数据源。