简体   繁体   English

有关Spring-boot-starter-data-jpa的问题

[英]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.

相关问题 Spring 引导不添加 spring-boot-starter-data-jpa - Spring boot not adding spring-boot-starter-data-jpa Java:依赖项目中的spring-boot-starter-data-jpa依赖 - Java : spring-boot-starter-data-jpa dependency in a dependent project spring-boot-starter-data-jpa依赖错误 - spring-boot-starter-data-jpa dependency error spring-boot-starter-data-jpa:自动重新连接 - spring-boot-starter-data-jpa : Auto Reconnect H2 数据库是用 spring-boot-starter-data-jpa 创建的,但不是用 spring-boot-starter-data-jdbc 创建的 - H2 Database created with spring-boot-starter-data-jpa but not with spring-boot-starter-data-jdbc spring-data-jpa和spring-boot-starter-data-jpa之间的区别 - Difference between spring-data-jpa and spring-boot-starter-data-jpa 在单元测试中带有spring-boot-starter-data-jpa的Spring Boot需要强制使用@DataJpaTest - Spring Boot with spring-boot-starter-data-jpa in unit test needs mandatory @DataJpaTest 未找到依赖项 &#39;org.springframework.boot:spring-boot-starter-data-jpa:2.5.3&#39; - Dependency 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.3' not found 将“spring-boot-starter-data-jpa”依赖项添加到Spring项目时出错 - Error when adding “spring-boot-starter-data-jpa” dependency to Spring project 为什么 spring-boot-starter-data-jpa 2.5.0 由于“找不到表”而无法初始化数据? - Why spring-boot-starter-data-jpa 2.5.0 can not init data by the cause "table not found"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM