【问题标题】:Spring boot (2.2.0.RELEASE<) with spring data rest endpoint not exposedSpring boot (2.2.0.RELEASE<) 没有暴露弹簧数据休息端点
【发布时间】:2020-02-20 19:26:22
【问题描述】:

我是 spring data rest 的新手,我的应用程序部署在我的 PC 上,但是当我访问 url(http://localhost:8080/) 时,会显示以下 json,而我的存储库中没有公开方法:

{
  "_links" : {
    "profile" : {
      "href" : "http://localhost:8080/profile"
    }
  }
}

请在下面找到 application.properties:

spring.datasource.url=jdbc:oracle:thin:@test:test1
spring.datasource.username=dummy
spring.datasource.password=dummy
spring.datasource.driver=class-oracle.jdbc.driver.OracleDriver


# HikariCP settings
# spring.datasource.hikari.*

spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5

spring.main.allow-bean-definition-overriding=true

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

我的仓库类如下:

public interface UsrAccessRepository extends PagingAndSortingRepository<UsrAccess, Long>{


    List<UsrAccess> findByUserId(@Param("userId") String userId);
//  
    List<UsrAccess> findAll();
}

当我访问以下 url http://localhost:8080/findAll 时,会抛出 404 错误。

我将此示例用作教程: https://www.baeldung.com/spring-data-rest-intro

知道我在这里缺少什么吗?

【问题讨论】:

    标签: java rest spring-boot spring-data-jpa


    【解决方案1】:

    您的UsrAccessRepository.java 必须与您的主类位于同一包树中(由@SpringBootApplication 注释)。

    默认情况下,Spring-Data-Rest 仅扫描主类包中和下的存储库接口。

    如果您的存储库是其他包,则使用@ComponentScan

    【讨论】:

      猜你喜欢
      • 2019-07-09
      • 2018-04-09
      • 2018-07-13
      • 2014-04-16
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      相关资源
      最近更新 更多