Spring Boot 2中的RepositoryRestResource注释无法访问

问题描述 投票:0回答:1

我似乎无法让@RepositoryRestResource处理我的简单课程。这是我的代码在GitHub上的位置:

https://github.com/txt8888/SB2-RepositoryRestResource

基本上,

部门实体:(我知道数据库连接有效)

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "departments")
public class Department {

    @Id
    private String id;
    private String name;
}

和存储库:

@CrossOrigin
@RepositoryRestResource(collectionResourceRel = "departments",
                        path = "departments")
public interface DepartmentRepository extends JpaRepository<Department, String> {
}

和我的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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>org.phan</groupId>
    <artifactId>hr</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Company HR</name>
    <description>Company Employees Manager System</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-core</artifactId>
            <version>2.6.10.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.6</version>
            <scope>provided</scope>
        </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>
            </plugin>
        </plugins>
    </build>

</project>

当我击中http://localhost:8080/departments时,它返回404未找到。

http://localhost:8080/actuator/mappings也没有显示终点。

我错过了一些明显的东西吗

spring-boot spring-data-jpa spring-boot-actuator
1个回答
1
投票

我发现了什么问题。我忘了包含这些依赖项:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

我之前有这种依赖:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-rest-core</artifactId>
    <version>2.6.10.RELEASE</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.