Java MongoDB+HibernateOGM+Spring Boot自动创建数据库
今天,我想使用Spring引导为MongoDB自动创建数据库结构。在过去的关系数据库中,我在application.properties文件中使用了两个属性,如:Java MongoDB+HibernateOGM+Spring Boot自动创建数据库,java,mongodb,spring-boot,hibernate-ogm,Java,Mongodb,Spring Boot,Hibernate Ogm,今天,我想使用Spring引导为MongoDB自动创建数据库结构。在过去的关系数据库中,我在application.properties文件中使用了两个属性,如: spring.jpa.hibernate.ddl-auto=create spring.jpa.generate-ddl=true 现在我想对MongoDB做同样的操作,但要使用属性: hibernate.ogm.datastore.create_database=true IntelliJ使用提示标记我的属性: cannot r
spring.jpa.hibernate.ddl-auto=create
spring.jpa.generate-ddl=true
现在我想对MongoDB做同样的操作,但要使用属性:
hibernate.ogm.datastore.create_database=true
IntelliJ使用提示标记我的属性:
cannot resolve configuration property hibernate.ogm.datastore.create_database
我的pom.xml看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.interview</groupId>
<artifactId>configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>configuration</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<hibernate.version>5.4.0.Final</hibernate.version>
<mapstruct.processor.version>1.3.0.Final</mapstruct.processor.version>
<mapstruct.version>1.3.0.Final</mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.processor.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的实体标记为annotation@Document,但在重新运行我的应用程序后,我仍然有一个空数据库
对于如何使用spring boot应用程序属性自动创建数据库的建议,我将不胜感激。然后,spring boot应用程序中等效的Hibernate属性应以spring.jpa.properties作为前缀。因此它应该是:
spring.jpa.properties.hibernate.ogm.datastore.create_database=true
然后,spring boot应用程序中等效的Hibernate属性应以spring.jpa.properties作为前缀。因此应为:
spring.jpa.properties.hibernate.ogm.datastore.create_database=true