简体   繁体   中英

Spring boot (2.2.0.RELEASE<) with spring data rest endpoint not exposed

I am new to spring data rest and I have my application deployed on my PC but when I access the url( http://localhost:8080/ ) the following json is displayed without the method exposed in my repository:

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

Please find below 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

My repository class is as follows:

public interface UsrAccessRepository extends PagingAndSortingRepository<UsrAccess, Long>{


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

When I access the following url http://localhost:8080/findAll a 404 error is thrown.

I used this example as tutorial: https://www.baeldung.com/spring-data-rest-intro

Any idea what i am missing here please?

Your UsrAccessRepository.java must be in the same package-tree than your main class (annotated by @SpringBootApplication ).

By default Spring-Data-Rest only scan for repository-interfaces in- and under the main class's package.

If your repository is an other package then use @ComponentScan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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