Java Spring引导(2.2.0.RELEASE<;),未公开Spring数据rest端点
我是spring data rest新手,我的应用程序部署在我的PC上,但当我访问url()时,会显示以下json,而不会在我的存储库中公开该方法:Java Spring引导(2.2.0.RELEASE<;),未公开Spring数据rest端点,java,rest,spring-boot,spring-data-jpa,Java,Rest,Spring Boot,Spring Data Jpa,我是spring data rest新手,我的应用程序部署在我的PC上,但当我访问url()时,会显示以下json,而不会在我的存储库中公开该方法: { "_links" : { "profile" : { "href" : "http://localhost:8080/profile" } } } 请查找以下application.properties: spring.datasource.url=jdbc:oracle:thin:@test:test1
{
"_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();
}
公共接口UsrAccessRepository扩展了分页和排序存储库{
列出findByUserId(@Param(“userId”)字符串userId);
//
列出findAll();
}
当我访问以下url时,抛出404错误
我将此示例用作教程:
你知道我这里缺少什么吗?你的
UsrAccessRepository.java
必须与你的主类位于同一个包树中(由@SpringBootApplication
注释)
默认情况下,SpringDataREST只扫描主类包中和包下的存储库接口
如果您的存储库是另一个包,那么使用
@ComponentScan
我没有看到任何用于处理/findAll
路径的控制器代码,那么为什么您认为该端点可以工作呢?--提示:存储库类不是Controllers.ohh,即使我有spring boot starter数据,其余的都在类路径上,我需要controller?我已经用我用作控制器的url更新了我的帖子example@Andreas当您使用它时,它可以自动将Spring数据存储库公开为REST资源,您不需要自己编写控制器。是的,对不起,我缺少数据部分。我以为你在问关于正常的春季MVC休息的问题如果您仔细阅读本文,则需要添加@RepositoryRestResource
以控制端点的路径,否则它默认为。。。嗯/usraccess
?能否尝试将注释添加到UsrAccessRepository
?