Spring boot Spring引导自动生成控制器

Spring boot Spring引导自动生成控制器,spring-boot,spring-data-jpa,spring-data-rest,Spring Boot,Spring Data Jpa,Spring Data Rest,在官方的Spring教程代码中,没有需要的控制器,因此我没有将它们放在示例中,但是当我尝试运行我的简单应用程序时,我一直在为错误寻找答案: 白标错误页面 此应用程序没有/error的显式映射,因此您可以看到 这是一种退路。2017年3月9日星期四10:18:51 CET有一个 意外错误(类型=未找到,状态=404)。没有可用的消息 结构: $ tree . ├── domain │   ├── Invoice.java │   └── InvoiceRepository.java ├── Qbs

在官方的Spring教程代码中,没有需要的控制器,因此我没有将它们放在示例中,但是当我尝试运行我的简单应用程序时,我一直在为错误寻找答案:

白标错误页面

此应用程序没有/error的显式映射,因此您可以看到 这是一种退路。2017年3月9日星期四10:18:51 CET有一个 意外错误(类型=未找到,状态=404)。没有可用的消息

结构:

$ tree
.
├── domain
│   ├── Invoice.java
│   └── InvoiceRepository.java
├── QbsApplication.java
invoice.java:

package qbs.domain;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
@Getter
@Setter
@ToString
public class Invoice {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String issuedBy;

    protected Invoice() {
    }
    public Invoice(String issuedBy) {
        this.issuedBy = issuedBy;
    }
}
回购:

1。有什么问题吗?

2。这是否是导致问题的lombok(尽管使用start.spring.io初始值设定项)?

编辑 Spring启动日志:

2017-03-09 11:12:43.233  INFO 16837 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-03-09 11:12:43.235  INFO 16837 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-03-09 11:12:43.236  INFO 16837 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-03-09 11:12:43.274  INFO 16837 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-03-09 11:12:43.370  INFO 16837 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2017-03-09 11:12:43.479  INFO 16837 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2017-03-09 11:12:43.481  INFO 16837 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@38ed139b
2017-03-09 11:12:43.695  WARN 16837 --- [           main] org.hibernate.orm.deprecation            : HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead.  See Hibernate Domain Model Mapping Guide for details.
2017-03-09 11:12:43.949  INFO 16837 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-03-09 11:12:44.464  INFO 16837 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6385cb26: startup date [Thu Mar 09 11:12:40 CET 2017]; root of context hierarchy
2017-03-09 11:12:44.546  INFO 16837 --- [           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.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-03-09 11:12:44.547  INFO 16837 --- [           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.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-03-09 11:12:44.576  INFO 16837 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.576  INFO 16837 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.614  INFO 16837 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.923  INFO 16837 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-03-09 11:12:44.988  INFO 16837 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-03-09 11:12:44.994  INFO 16837 --- [           main] qbs.QbsApplication                       : Started QbsApplication in 4.875 seconds (JVM running for 5.356)
2017-03-09 11:12:43.233信息16837---[main]org.hibernate.Version:hh000412:hibernate核心{5.0.12.Final}
2017-03-09 11:12:43.235信息16837---[main]org.hibernate.cfg.Environment:hh000206:hibernate.properties未找到
2017-03-09 11:12:43.236信息16837---[main]org.hibernate.cfg.Environment:hh000021:字节码提供程序名称:javassist
2017-03-09 11:12:43.274信息16837---[main]o.hibernate.annotations.common.Version:HCANN000001:hibernate Commons annotations{5.0.1.Final}
2017-03-09 11:12:43.370信息16837---[main]org.hibernate.dialen.dialen:hh000400:使用方言:org.hibernate.dialen.postgresqldiante
2017-03-09 11:12:43.479信息16837---[main]o.h.e.j.e.i.LobCreatorBuilderImpl:hh000424:禁用上下文LOB创建作为createClob()方法引发错误:java.lang.reflect.InvocationTargetException
2017-03-09 11:12:43.481信息16837---[main]org.hibernate.type.BasicTypeRegistry:hh000270:type registration[java.util.UUID]覆盖先前的:org.hibernate.type。UUIDBinaryType@38ed139b
2017-03-09 11:12:43.695警告16837---[main]org.hibernate.orm.deprecation:HHH90000014:发现使用了不推荐的[org.hibernate.id.SequenceGenerator]基于序列的id生成器;改用org.hibernate.id.enhanced.SequenceStyleGenerator。有关详细信息,请参阅《Hibernate域模型映射指南》。
2017-03-09 11:12:43.949 INFO 16837---[main]j.localcontainerentitymanagerfactorbean:为持久化单元“default”初始化了JPA EntityManagerFactory
2017-03-09 11:12:44.464信息16837---[main]s.w.s.m.m.a.RequestMappingHandlerAdapter:正在寻找@ControllerAdvice:org.springframework.boot.context.embedded。AnnotationConfigEmbeddedWebApplicationContext@6385cb26:启动日期[2017年3月9日星期四11:12:40 CET];上下文层次结构的根
2017-03-09 11:12:44.546 INFO 16837-[main]s.w.s.m.m.a.RequestMappingHandlerMapping:将“{[/error],products=[text/html]}”映射到public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-03-09 11:12:44.547 INFO 16837---[main]s.w.s.m.a.RequestMappingHandlerMapping:将“{[/error]}”映射到public org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-03-09 11:12:44.576 INFO 16837---[main]o.s.w.s.handler.simplerlhandler映射:将URL路径[/webjars/**]映射到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序上
2017-03-09 11:12:44.576 INFO 16837---[main]o.s.w.s.handler.SimpleUrlHandlerMapping:将URL路径[/**]映射到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序上
2017-03-09 11:12:44.614 INFO 16837---[main]o.s.w.s.handler.simplerlhandlermapping:将URL路径[/**/favicon.ico]映射到[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]类型的处理程序上
2017-03-09 11:12:44.923信息16837---[main]o.s.j.e.a.注释MBeanExporter:在启动时为JMX暴露注册bean
2017-03-09 11:12:44.988信息16837---[main]s.b.c.e.t.TomcatEmbeddedServletContainer:Tomcat在端口8080(http)上启动
2017-03-09 11:12:44.994信息16837---[main]qbs.qbs应用程序:在4.875秒内启动qbs应用程序(JVM运行5.356)

您忘了用
@RepositoryRestResource
注释存储库。如果不这样做,Spring将不会自动生成url映射,它将只是作为一个普通的存储库。这是spring数据rest的一个特性。因此,在你的情况下:

@RepositoryRestResource(collectionResourceRel = "invoices", path = "invoices")
public interface InvoiceRepository extends PagingAndSortingRepository<Invoice, Long> {
    List<Invoice> findByIssuedBy(@Param("issuer")String issuer);
}
@RepositoryRestResource(collectionResourceRel=“invoices”,path=“invoices”)
公共接口InvoiceRepository扩展了分页和排序存储库{
列表findByIssuedBy(@Param(“发卡机构”)字符串发卡机构);
}
现在
curlhttp://localhost:8080/invoices
将返回所有发票


有关更多信息,请参阅。

谢谢您的回复。不过,我检查了教程:它指出导出存储库不需要“@RepositoryRestResource”。它仅用于更改导出详细信息,例如使用/people而不是默认值/people。您可以参考此信息吗,因为我发现他们的提示有点误导性?即使在复制粘贴代码并检查链接之后
2017-03-09 11:12:43.233  INFO 16837 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-03-09 11:12:43.235  INFO 16837 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-03-09 11:12:43.236  INFO 16837 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-03-09 11:12:43.274  INFO 16837 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-03-09 11:12:43.370  INFO 16837 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2017-03-09 11:12:43.479  INFO 16837 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2017-03-09 11:12:43.481  INFO 16837 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@38ed139b
2017-03-09 11:12:43.695  WARN 16837 --- [           main] org.hibernate.orm.deprecation            : HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead.  See Hibernate Domain Model Mapping Guide for details.
2017-03-09 11:12:43.949  INFO 16837 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-03-09 11:12:44.464  INFO 16837 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6385cb26: startup date [Thu Mar 09 11:12:40 CET 2017]; root of context hierarchy
2017-03-09 11:12:44.546  INFO 16837 --- [           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.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-03-09 11:12:44.547  INFO 16837 --- [           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.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-03-09 11:12:44.576  INFO 16837 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.576  INFO 16837 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.614  INFO 16837 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-09 11:12:44.923  INFO 16837 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-03-09 11:12:44.988  INFO 16837 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-03-09 11:12:44.994  INFO 16837 --- [           main] qbs.QbsApplication                       : Started QbsApplication in 4.875 seconds (JVM running for 5.356)
@RepositoryRestResource(collectionResourceRel = "invoices", path = "invoices")
public interface InvoiceRepository extends PagingAndSortingRepository<Invoice, Long> {
    List<Invoice> findByIssuedBy(@Param("issuer")String issuer);
}