【问题标题】:RepositoryRestResource with spring-boot CLI使用 spring-boot CLI 的 RepositoryRestResource
【发布时间】:2014-10-07 22:58:48
【问题描述】:

我正在尝试基于带有 spring-boot 和 spring-data-rest 的 JPA 存储库实现一个简单的 REST 服务。 (见tutorial)如果将以下代码与gradle一起使用,则效果很好:

package ch.bfh.swos.bookapp

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.annotation.*
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.context.annotation.Import
import org.springframework.data.rest.core.annotation.RepositoryRestResource
import org.springframework.data.repository.CrudRepository
import javax.persistence.*

@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableJpaRepositories
@Import(RepositoryRestMvcConfiguration.class)
class Application {
    static void main(String[] args) {
        SpringApplication.run Application, args
    }
}

@RepositoryRestResource(path = "authors")
interface AuthorRepository extends CrudRepository<Author, Long> {}

@Entity
class Author {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id
    private String firstname
    private String lastname
}

为了让事情变得更简单,我用 spring boot CLI(“spring run”命令)尝试了相同的代码。

package ch.bfh.swos.bookapp

@Grab("spring-boot-starter-data-jpa")
@Grab("spring-boot-starter-data-rest")
@Grab("h2")

import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.context.annotation.Import

import org.springframework.data.rest.core.annotation.RepositoryRestResource
import org.springframework.data.repository.CrudRepository

import javax.persistence.*

@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableJpaRepositories
@Import(RepositoryRestMvcConfiguration.class)
@RepositoryRestResource(path = "authors")
interface AuthorRepository extends CrudRepository<Author, Long> {}

@Entity
class Author {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id
    private String firstname
    private String lastname
}

不幸的是,这似乎不起作用。 @RepositoryRestResource 似乎不会被自动识别,例如@RestController。 保留@Configuration 部分,服务器会启动,但不会像使用 gradle 那样创建 REST 存储库。

有人知道是否可以使用 spring-boot CLI 创建 RepositoryRestResource 以及正确的代码应该是什么样子?

【问题讨论】:

    标签: spring-boot spring-data-rest


    【解决方案1】:

    您需要一个类定义来挂起@Import(在一个类而不是接口上的其他注释是多余的)。

    更新:(更重要的是)Hibernate 无法找到带注释的类,除非它们实际上在文件中(它会反射分析字节码而不是类定义)。因此,您可以通过震荡并以这种方式运行它来让您的应用正常工作:

    $ spring jar app.jar app.groovy
    $ java -jar app.jar
    

    这是应用程序的一个更短的版本,它的工作原理与此类似,删除了所有多余的东西:

    package bookapp
    
    @Grab("spring-boot-starter-data-jpa")
    @Grab("spring-boot-starter-data-rest")
    @Grab("h2")
    
    import org.springframework.data.rest.core.annotation.RepositoryRestResource
    import org.springframework.data.repository.CrudRepository
    
    import javax.persistence.*
    
    @Configuration
    class App {}  
    
    @RepositoryRestResource(path = "authors")
    interface AuthorRepository extends CrudRepository<Author, Long> {}
    
    @Entity
    class Author {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id
      String firstname
      String lastname
    }
    

    【讨论】:

    • 我想将@Import 添加到一个类(应用程序类)中。但不幸的是,Spring Boot CLI 创建了它自己的应用程序类(如 here 所述)。不幸的是,我找不到自定义应用程序类的方法,因此我可以添加自己的导入语句。
    • 感谢您的耐心等待 ;-)。用 App 类尝试过,但这也不起作用。有关新的(不工作的)代码和日志,请参阅我的以下“答案”。
    • 嘿酷!那行得通!那么问题不是 Spring Boot 没有找到 Spring Data REST 注释,而是 Hibernate 在编译代码之前没有找到 Entity 注释。我可以忍受这一点。非常感谢您的帮助。
    【解决方案2】:

    按照 Dave 的建议,我尝试将 @Import 语句添加到类“App”中。现在的代码如下所示。

    package ch.bfh.swos.bookapp
    
    @Grab("spring-boot-starter-data-jpa")
    @Grab("spring-boot-starter-data-rest")
    @Grab("h2")
    
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration
    import org.springframework.context.annotation.Configuration
    import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration
    import org.springframework.data.jpa.repository.config.EnableJpaRepositories
    import org.springframework.context.annotation.Import
    
    import org.springframework.data.rest.core.annotation.RepositoryRestResource
    import org.springframework.data.repository.CrudRepository
    
    import javax.persistence.*
    
    @Configuration
    @EnableJpaRepositories
    @Import(RepositoryRestMvcConfiguration.class)
    @EnableAutoConfiguration
    class App {}
    
    @RepositoryRestResource(path = "authors")
    interface AuthorRepository extends CrudRepository<Author, Long> {}
    
    @Entity
    class Author {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id
        private String firstname
        private String lastname
    }
    

    不幸的是,这也不起作用。 Spring Data Rest 似乎已正确初始化,但 RepositoryRestResource 只是被忽略了。调用 localhost:8080 只会显示 { }。 还有什么建议吗?

    这里是 Spring Boot 日志的输出:

      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v1.1.5.RELEASE)
    
    2014-09-03 10:24:09.061  INFO 6264 --- [       runner-0] o.s.boot.SpringApplication               : Starting application on MIMA-WS-00 with PID 6264 (C:\development\maven\repository\org\springframework\boot\spring-boot\1.1.5.RELEASE\spring-boot-1.1.5.RELEASE.jar started by rovi in C:\Users\rovi\Desktop\springboot)
    2014-09-03 10:24:09.261  INFO 6264 --- [       runner-0] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@62149bcb: startup date [Wed Sep 03 10:24:09 CEST 2014]; root of context hierarchy
    2014-09-03 10:24:10.248  INFO 6264 --- [       runner-0] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
    2014-09-03 10:24:10.502  INFO 6264 --- [       runner-0] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'jpaMapppingContext': replacing [Root bean: class [org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension$JpaMetamodelMappingContextFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension$JpaMetamodelMappingContextFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
    2014-09-03 10:24:11.293  INFO 6264 --- [       runner-0] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$3e485a8b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2014-09-03 10:24:11.331  INFO 6264 --- [       runner-0] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2014-09-03 10:24:11.346  INFO 6264 --- [       runner-0] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2014-09-03 10:24:11.359  INFO 6264 --- [       runner-0] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2014-09-03 10:24:11.879  INFO 6264 --- [       runner-0] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
    2014-09-03 10:24:12.045  INFO 6264 --- [       runner-0] o.apache.catalina.core.StandardService   : Starting service Tomcat
    2014-09-03 10:24:12.049  INFO 6264 --- [       runner-0] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.54
    2014-09-03 10:24:12.212  INFO 6264 --- [ost-startStop-1] org.apache.catalina.loader.WebappLoader  : Unknown loader org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@19d59bb2 class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader
    2014-09-03 10:24:12.222  INFO 6264 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2014-09-03 10:24:12.223  INFO 6264 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2965 ms
    2014-09-03 10:24:14.121  INFO 6264 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
    2014-09-03 10:24:14.133  INFO 6264 --- [ost-startStop-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
    2014-09-03 10:24:14.233  INFO 6264 --- [ost-startStop-1] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.5.Final}
    2014-09-03 10:24:14.237  INFO 6264 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
    2014-09-03 10:24:14.239  INFO 6264 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
    2014-09-03 10:24:14.455  INFO 6264 --- [ost-startStop-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
    2014-09-03 10:24:14.546  INFO 6264 --- [ost-startStop-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
    2014-09-03 10:24:14.640  INFO 6264 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
    2014-09-03 10:24:14.826  INFO 6264 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
    2014-09-03 10:24:14.835  INFO 6264 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
    2014-09-03 10:24:15.437  INFO 6264 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
    2014-09-03 10:24:15.440  INFO 6264 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
    2014-09-03 10:24:15.943  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws java.lang.Exception
    2014-09-03 10:24:15.944  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}/{propertyId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,java.lang.String,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws java.lang.Exception
    2014-09-03 10:24:15.947  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<? extends org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.deletePropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String) throws java.lang.Exception
    2014-09-03 10:24:15.950  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[GET],params=[],headers=[],consumes=[],produces=[application/x-spring-data-compact+json || text/uri-list],custom=[]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReferenceCompact(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws java.lang.Exception
    2014-09-03 10:24:15.953  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[PATCH || PUT],params=[],headers=[],consumes=[application/json || application/x-spring-data-compact+json || text/uri-list],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<? extends org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.createPropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.http.HttpMethod,org.springframework.hateoas.Resources<java.lang.Object>,java.io.Serializable,java.lang.String) throws java.lang.Exception
    2014-09-03 10:24:15.954  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}/{propertyId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.deletePropertyReferenceId(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,java.lang.String) throws java.lang.Exception
    2014-09-03 10:24:15.957  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/schema],methods=[GET],params=[],headers=[],consumes=[],produces=[application/schema+json],custom=[]}" onto public org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.json.JsonSchema> org.springframework.data.rest.webmvc.RepositorySchemaController.schema(org.springframework.data.rest.webmvc.RootResourceInformation)
    2014-09-03 10:24:15.960  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[HEAD],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation) throws org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.960  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.hateoas.Resources<?> org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.domain.Pageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.961  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[GET],params=[],headers=[],consumes=[],produces=[application/x-spring-data-compact+json || text/uri-list],custom=[]}" onto public org.springframework.hateoas.Resources<?> org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResourceCompact(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.domain.Pageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.961  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.postCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource<?>,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.962  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[PATCH],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.patchItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource<java.lang.Object>,java.io.Serializable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.web.HttpRequestMethodNotSupportedException,org.springframework.data.rest.webmvc.ResourceNotFoundException
    2014-09-03 10:24:15.962  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.deleteItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.963  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[HEAD],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.headItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable) throws org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.966  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.Resource<?>> org.springframework.data.rest.webmvc.RepositoryEntityController.getItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.966  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[PUT],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<? extends org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.putItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource<java.lang.Object>,java.io.Serializable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.web.HttpRequestMethodNotSupportedException
    2014-09-03 10:24:15.968  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.data.rest.webmvc.RepositoryLinksResource org.springframework.data.rest.webmvc.RepositoryController.listRepositories()
    2014-09-03 10:24:15.970  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search/{search}],methods=[GET],params=[],headers=[],consumes=[],produces=[application/x-spring-data-compact+json],custom=[]}" onto public org.springframework.hateoas.ResourceSupport org.springframework.data.rest.webmvc.RepositorySearchController.executeSearchCompact(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.web.context.request.WebRequest,java.lang.String,java.lang.String,org.springframework.data.domain.Pageable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler)
    2014-09-03 10:24:15.970  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.hateoas.ResourceSupport org.springframework.data.rest.webmvc.RepositorySearchController.listSearches(org.springframework.data.rest.webmvc.RootResourceInformation)
    2014-09-03 10:24:15.970  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search/{search}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.lang.Object> org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.web.context.request.WebRequest,java.lang.String,org.springframework.data.domain.Pageable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler)
    2014-09-03 10:24:15.971  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search],methods=[HEAD],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.RepositorySearchController.headForSearches(org.springframework.data.rest.webmvc.RootResourceInformation)
    2014-09-03 10:24:15.971  INFO 6264 --- [       runner-0] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search/{search}],methods=[HEAD],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.lang.Object> org.springframework.data.rest.webmvc.RepositorySearchController.headForSearch(org.springframework.data.rest.webmvc.RootResourceInformation,java.lang.String)
    2014-09-03 10:24:16.214  INFO 6264 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2014-09-03 10:24:16.281  INFO 6264 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" 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)
    2014-09-03 10:24:16.281  INFO 6264 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
    2014-09-03 10:24:16.300  INFO 6264 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2014-09-03 10:24:16.300  INFO 6264 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    2014-09-03 10:24:16.530  INFO 6264 --- [       runner-0] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    2014-09-03 10:24:16.658  INFO 6264 --- [       runner-0] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
    2014-09-03 10:24:16.661  INFO 6264 --- [       runner-0] o.s.boot.SpringApplication               : Started application in 7.952 seconds (JVM running for 10.109)
    2014-09-03 10:24:27.951  INFO 6264 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
    2014-09-03 10:24:27.952  INFO 6264 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
    2014-09-03 10:24:27.974  INFO 6264 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 22 ms
    

    【讨论】:

      【解决方案3】:

      虽然我迟到了,但请检查以下是否对您有帮助。

      我有一个使用 RepositoryRestResource 和 EntityLinks 的工作示例和博客。请检查这是否对您有帮助。在博客上你也可以找到 GitHub 链接。

      http://sv-technical.blogspot.com/2015/11/spring-boot-and-repositoryrestresource.html

      【讨论】:

        猜你喜欢
        • 2017-08-31
        • 2018-01-29
        • 2016-12-16
        • 2015-07-08
        • 2014-08-25
        • 1970-01-01
        • 2020-01-08
        • 2017-07-24
        • 2021-11-07
        相关资源
        最近更新 更多