[英]A question about the Spring-boot-starter-data-jpa
The Spring Boot Starter Data JPA dependency indeed have some good configs by default, it just picks the information from my application.properties, right? 默认情况下,Spring Boot Starter Data JPA依赖项确实具有一些不错的配置,它只是从我的application.properties中选择信息,对吗?
Unfortunately, my project doesn't recognize its configurations. 不幸的是,我的项目无法识别其配置。 I'm forced to do a config class to run my project.
我被迫做一个配置类来运行我的项目。 My Eclipse don't show any
pom.xml
error either. 我的Eclipse也不显示任何
pom.xml
错误。 In my pom.xml
, I simply got this warning: The managed version is 2.0.2.RELEASE
The artifact is managed in org.springframework.boot:spring-boot-dependencies:2.0.2.RELEASE
在我的
pom.xml
,我仅收到以下警告:托管版本为2.0.2.RELEASE
该工件在org.springframework.boot:spring-boot-dependencies:2.0.2.RELEASE
Here's my pom.xml: 这是我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jequiti</groupId>
<artifactId>Projeto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>IntegraPedidos</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!-- JDBC -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.4.Final</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
<!-- Repository for ORACLE JDBC Driver -->
<repositories>
<!-- Repository for ORACLE JDBC Driver -->
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
And this is my properties file: 这是我的属性文件:
#===============================
#JPA / HIBERNATE
#===============================
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
You should use following properties to make spring data jpa work as expected. 您应该使用以下属性来使spring数据jpa正常工作。
spring.jpa.hibernate.ddl-auto = none
spring.jpa.properties.hibernate.show_sql = true
spring.jpa.properties.hibernate.format_sql = true
Setting ddl-auto = none
will not change your database schema even if your Mapped Entity class has changed. 设置
ddl-auto = none
不会更改数据库架构,即使您的“映射实体”类已更改。 It is not recommended to use none
unless you are really sure what you are trying to achieve. 不建议使用
none
,除非你真的确定你想要达到的目的。
Setting show_sql = true
will log the sql statements executed by hibernate. 设置
show_sql = true
将记录由hibernate执行的sql语句。
Setting format_sql = true
will format the sql statement logs into more readable form. 设置
format_sql = true
会将sql语句日志格式化为更易读的形式。 However, it is not necessary step in order to get logs printed.. it is just for readability. 但是,这不是为了打印日志而必需的步骤。它只是为了提高可读性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.