Java spring data RepositoryRestResource未映射到spring boot app中的端点

Java spring data RepositoryRestResource未映射到spring boot app中的端点,java,spring,hibernate,spring-boot,spring-data,Java,Spring,Hibernate,Spring Boot,Spring Data,我一直在尝试使用SpringDataREST和SpringBoot设置rest服务。我在上遵循了教程,但预期的rest端点并不是在启动时创建的,对它们调用get方法只会导致404错误。我可以使用RestController创建端点,但不能使用RepositoryRestResource。我使用SpringBoot2和Hibernate5.2,postgres作为后台数据存储。我正在使用eclipse,并尝试通过在eclipse中运行Java应用程序来运行该应用程序,以及使用Java-jar从wi

我一直在尝试使用SpringDataREST和SpringBoot设置rest服务。我在上遵循了教程,但预期的rest端点并不是在启动时创建的,对它们调用get方法只会导致404错误。我可以使用RestController创建端点,但不能使用RepositoryRestResource。我使用SpringBoot2和Hibernate5.2,postgres作为后台数据存储。我正在使用eclipse,并尝试通过在eclipse中运行Java应用程序来运行该应用程序,以及使用Java-jar从windows命令行运行它。输出和最终结果是相同的。有人知道我做错了什么,以及我需要为RepositoryRestResource创建的预期端点做什么吗?下面是示例代码,底部是spring boot输出,但首先是一些类似的问题和我尝试过的内容:

这个问题有一个公认的答案,似乎表明它是一个实体扫描问题。但是,我在应用程序中添加了EntityScan,这似乎没有什么帮助。

这个问题的答案是建议使用RestController将存储库包装在控制器类中,而不是使用RepositoryRestResource。我可以这样做,但我不想写所有额外的代码,我宁愿让RepositoryRestResource工作。

项目结构:

pom.xml  

src/main/java/com/springdataresttest/  
Application.java  
src/main/java/com/springdataresttest/entity/  
Thing.java
src/main/java/com/springdataresttest/repository/  
ThingRepository.java  

src/main/resources/  
application.properties  
hibernate.properties  
postgres ddl:

CREATE TABLE thing
(
    id serial,
    name varchar(255),
    PRIMARY KEY (id)
)
pom.xml:

<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>
  <groupId>com.springdataresttest</groupId>
  <artifactId>springdataresttest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </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>
Thing.java:

package com.springdataresttest.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "thing")
public class Thing {

    private Integer id;
    private String name;

    @Id
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
ThingRepository.java:

package com.springdataresttest.repository;

import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import com.springdataresttest.entity.Thing;

@RepositoryRestResource(collectionResourceRel = "things", path = "things")
public interface ThingRepository extends PagingAndSortingRepository<Thing, Integer>{

}
hibernate.properties:

security.basic.enabled=false
management.security.enabled=false
security.ignored=/**

spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/springdataresttest
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=none
spring.datasource.platform=POSTGRESQL
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql://127.0.0.1:5432/springdataresttest
hibernate.connection.username=postgres
hibernate.connection.password=password
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.schema=public
spring引导的输出(请注意,“东西”的rest存储库端点没有映射)

。\uuuuuuuuuuuu_
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
'  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
::弹簧启动::(v2.0.3.版本)
2018-08-23 14:57:51.118 INFO 1336---[main]com.springdatarestest.Application:使用PID 1336在LTW10me上启动应用程序(C:\Users\me.HQ\workspace\springdatarestest\target\classes由我在C:\Users\me.HQ\workspace\springdatarestest中启动)
2018-08-23 14:57:51.123信息1336---[main]com.springdatarestest.Application:未设置活动配置文件,返回默认配置文件:默认
2018-08-23 14:57:51.233信息1336---[main]配置ServletWebServerApplicationContext:刷新org.springframework.boot.web.servlet.context。AnnotationConfigServletWebServerApplicationContext@6646153:启动日期[2018年8月23日星期四14:57:51美国东部夏令时];上下文层次结构的根
2018-08-23 14:57:52.882信息1336---[main]trationlegate$BeanPostProcessorChecker:Bean'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration'类型为[org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ca53dd09]不符合由所有BeanPostProcessor处理的条件(例如:不符合自动代理的条件)
2018-08-23 14:57:53.548信息1336---[main]o.s.b.w.embedded.tomcat.TomcatWebServer:tomcat已用端口初始化:8080(http)
2018-08-23 14:57:53.583信息1336---[main]o.apache.catalina.core.StandardService:启动服务[Tomcat]
2018-08-23 14:57:53.583信息1336---[main]org.apache.catalina.core.StandardEngine:启动Servlet引擎:ApacheTomcat/8.5.31
2018-08-23 14:57:53.593信息1336-[ost-startStop-1]o.a.catalina.core.AprLifecycleListener:在java.library.path上找不到基于APR的Apache Tomcat本机库,该库允许在生产环境中实现最佳性能:[C:\Program Files\Java\jdk1.8.0\u 112\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0\u 171/bin/server;C:/Program Files/Java/jre1.8.0\u 171/lib/amd64;C:\Program Files(x86)\公共文件\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\Wbem;C:\WINDOWS\system32\WindowsPowerShell\v1.0\;C:\Program Files(x86)\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files(x86)\Bitvise SSH客户端;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\Program Files(x86)\Thread\bin\;C:\Program Files\nodejs\;C:\WINDOWS\System32\OpenSSH\;“C:\Users\me.HQ\AppData\Local\Microsoft\WindowsApps;C:\Program Files(x86)\PuTTY;C:\Program Files\PostgreSQL\9.6\bin;C:\cygwin64;C;\cygwin64\bin;”;C:\Users\me.HQ\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\Microsoft VS Code\bin;C:\Users\me.HQ\AppData\Local\Thread\bin;C:\Users\me.HQ\AppData\Roaming\npm;C:\eclipse;;。]
2018-08-23 14:57:53.709信息1336---[ost-startStop-1]o.a.c.c.c.[Tomcat].[localhost].[/]:初始化Spring嵌入式WebApplicationContext
2018-08-23 14:57:53.709信息1336---[ost-startStop-1]o.s.web.context.ContextLoader:根WebApplicationContext:初始化在2481毫秒内完成
2018-08-23 14:57:53.876信息1336---[ost-startStop-1]o.s.b.w.servlet.ServletRegistrationBean:ServletDispatchersServlet映射到[/]
2018-08-23 14:57:53.881信息1336---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“characterEncodingFilter”映射到:[/*]
2018-08-23 14:57:53.881信息1336---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“hiddenHttpMethodFilter”映射到:[/*]
2018-08-23 14:57:53.881信息1336---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“httpPutFormContentFilter”映射到:[/*]
2018-08-23 14:57:53.886信息1336---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“requestContextFilter”映射到:[/*]
2018-08-23 14:57:54.138信息1336---[main]com.zaxxer.hikari.HikariDataSource:hikaripol-1-开始。。。
2018-08-23 14:57:54.720信息1336---[main]com.zaxxer.hikari
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql://127.0.0.1:5432/springdataresttest
hibernate.connection.username=postgres
hibernate.connection.password=password
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.schema=public
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)

2018-08-23 14:57:51.118  INFO 1336 --- [           main] com.springdataresttest.Application       : Starting Application on LTW10me with PID 1336 (C:\Users\me.HQ\workspace\springdataresttest\target\classes started by me in C:\Users\me.HQ\workspace\springdataresttest)
2018-08-23 14:57:51.123  INFO 1336 --- [           main] com.springdataresttest.Application       : No active profile set, falling back to default profiles: default
2018-08-23 14:57:51.233  INFO 1336 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6646153: startup date [Thu Aug 23 14:57:51 EDT 2018]; root of context hierarchy
2018-08-23 14:57:52.882  INFO 1336 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ca53dd09] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-23 14:57:53.548  INFO 1336 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-08-23 14:57:53.583  INFO 1336 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-08-23 14:57:53.583  INFO 1336 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-08-23 14:57:53.593  INFO 1336 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_112\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_171/bin/server;C:/Program Files/Java/jre1.8.0_171/bin;C:/Program Files/Java/jre1.8.0_171/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\nodejs\;C:\WINDOWS\System32\OpenSSH\;"C:\Users\me.HQ\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\PuTTY;C:\Program Files\PostgreSQL\9.6\bin;C:\cygwin64;C;\cygwin64\bin;";C:\Users\me.HQ\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\Microsoft VS Code\bin;C:\Users\me.HQ\AppData\Local\Yarn\bin;C:\Users\me.HQ\AppData\Roaming\npm;C:\eclipse;;.]
2018-08-23 14:57:53.709  INFO 1336 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-08-23 14:57:53.709  INFO 1336 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2481 ms
2018-08-23 14:57:53.876  INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-08-23 14:57:53.881  INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-08-23 14:57:53.881  INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-08-23 14:57:53.881  INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-08-23 14:57:53.886  INFO 1336 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-08-23 14:57:54.138  INFO 1336 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-08-23 14:57:54.720  INFO 1336 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2018-08-23 14:57:54.768  INFO 1336 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-08-23 14:57:54.793  INFO 1336 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-08-23 14:57:54.944  INFO 1336 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.17.Final}
2018-08-23 14:57:54.947  INFO 1336 --- [           main] org.hibernate.cfg.Environment            : HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.username=postgres, hibernate.schema=public, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect, hibernate.connection.url=jdbc:postgresql://127.0.0.1:5432/springdataresttest, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=org.postgresql.Driver}
2018-08-23 14:57:55.015  INFO 1336 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-08-23 14:57:55.155  WARN 1336 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata : null
2018-08-23 14:57:55.168  INFO 1336 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2018-08-23 14:57:55.188  INFO 1336 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000422: Disabling contextual LOB creation as connection was null
2018-08-23 14:57:55.193  INFO 1336 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@64f16277
2018-08-23 14:57:55.716  INFO 1336 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-08-23 14:57:55.851  INFO 1336 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-23 14:57:56.594  INFO 1336 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6646153: startup date [Thu Aug 23 14:57:51 EDT 2018]; root of context hierarchy
2018-08-23 14:57:56.653  WARN 1336 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-08-23 14:57:56.698  INFO 1336 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-08-23 14:57:56.703  INFO 1336 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-08-23 14:57:56.748  INFO 1336 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-23 14:57:56.749  INFO 1336 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-23 14:57:57.112  INFO 1336 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-08-23 14:57:57.115  INFO 1336 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-08-23 14:57:57.120  INFO 1336 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-08-23 14:57:57.170  INFO 1336 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-08-23 14:57:57.180  INFO 1336 --- [           main] com.springdataresttest.Application       : Started Application in 6.496 seconds (JVM running for 6.954)