Java Spring Hibernate.ddl-auto:不以任何方式覆盖属性 [英] Java spring hibernate.ddl-auto: none property is somehow overrided
问题描述
我在使用hibernate.ddl-auto时遇到问题:春季没有问题.它在开发环境中运行良好,并且不执行sql类的drop table.但是在生产环境中,相同的属性似乎不起作用.并执行drop并创建表sql.在application.yaml生产中:
I have problem with hibernate.ddl-auto: none in spring. It works fine in development environment and does not execute sql's like drop table. But in production environment same property seems like it's not working. And execute drop and create tables sql's. In application.yaml on production:
spring:
jpa:
hibernate.ddl-auto: none
我通过以下方式在应用程序中检查了该值:
I checked this value in application by this:
@Bean
public CommandLineRunner initProject() {
return (args) -> {
logger.info(env.getProperty("spring.jpa.hibernate.ddl-auto")); //this prints "create"
因此,似乎某些内部代码更改了它的值.我通过以下命令运行应用程序:
So it looks like some internal code changed it value. I run application by this command:
./mvnw spring-boot:run
推荐答案
该值必须来自某处...
The value has to come from somewhere...
如果启用了 actuator
,您可以轻松地对此进行跟踪
You can easily trace this if you have actuator
enabled
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
并通过
management:
endpoints:
web:
exposure:
include: env
然后,您可以通过/actuator/env
访问该端点在这里甚至可以找到定义值的位置.
Then you can visit that endpoint via /actuator/env
Here you can even find the location where you have defined the value.
{
"name": "Config resource 'class path resource [application.yaml]' via location 'optional:classpath:/'",
"properties": {
"spring.jpa.hibernate.ddl-auto": {
"value": "none",
"origin": "class path resource [application.yaml] - 3:25"
},
"management.endpoints.web.exposure.include": {
"value": "env",
"origin": "class path resource [application.yaml] - 9:18"
}...
这篇关于Java Spring Hibernate.ddl-auto:不以任何方式覆盖属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!