简体   繁体   English

Spring 引导项目未从数据库重新加载数据

[英]Spring boot project not reloading data from database

i have been working on a full stack application using angular and spring boot for the first time (i'm following a full project tutorial),我第一次使用 angular 和 spring 引导开发完整的堆栈应用程序(我正在关注完整的项目教程),

i downloaded a project from https://start.spring.io/ and added the following dependencies;我从https://start.spring.io/下载了一个项目并添加了以下依赖项; mySQL driver, lombok, spring data JPA and REST repositories.after working on my project and executing it,i found out that the data are not loaded from the database (PS: database not empty): and here's my execution result mySQL driver, lombok, spring data JPA and REST repositories.after working on my project and executing it,i found out that the data are not loaded from the database (PS: database not empty): and here's my execution result

: while this is the tutor's result :虽然这是导师的结果

i ingore it and tried to consume the data in the front end using angular and this is my result我拒绝它并尝试使用 angular 在前端消耗数据,这是我的结果

while this is my tutor's results虽然这是我导师的结果

i'll share with you my application propreties here:我将在这里与您分享我的应用程序属性:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/full-stack-ecommerce?useSSL=false&useUnicode=yes&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&serverTimezone=UTC
spring.datasource.username=ecommerceapp
spring.datasource.password=ecommerceapp

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

spring.data.rest.base-path=/api

server.port=9091

and 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 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.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.luv2code</groupId>
    <artifactId>spring-boot-ecommerce</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-ecommerce</name>
    <description>Spring Boot Ecommerce Project</description>
    <properties>
        <java.version>17</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>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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</groupId> 
                    <artifactId>hibernate-core</artifactId> 
                     
</dependency>
<dependency> 
                      <groupId>org.hibernate</groupId> 
                      <artifactId>hibernate-entitymanager</artifactId> 
                      </dependency>
<dependency> 
                        <groupId>javax.xml.bind</groupId> 
                        <artifactId>jaxb-api</artifactId> 
                        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>


i truly appreciate any help我真的很感激任何帮助

Im doing exactly the same Chad project now, everything works, Java 17 and spring 2.6.1我现在正在做完全相同的乍得项目,一切正常,Java 17 和 spring 2.6.1

here is application properties (i changed username, password):这是应用程序属性(我更改了用户名、密码):

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/full-stack-ecommerce?useSSL=false&useUnicode=yes&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&serverTimezone=UTC
spring.datasource.username=angfullecom
spring.datasource.password=angfullecom

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

spring.data.rest.base-path=/api

As you see i dont have your line: server.port=9091如您所见,我没有您的线路:server.port=9091

my pom file:我的 pom 文件:

<?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.6.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ilze</groupId>
    <artifactId>full-ang-ecommerce</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>full-ang-ecommerce</name>
    <description>Spring Boot Angular Ecommerce Project</description>
    <properties>
        <java.version>17</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>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Did you accessed the project using address http://localhost:8080/api/products?您是否使用地址 http://localhost:8080/api/products 访问了该项目?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM