• <small id='WJMZU'></small><noframes id='WJMZU'>

    <i id='WJMZU'><tr id='WJMZU'><dt id='WJMZU'><q id='WJMZU'><span id='WJMZU'><b id='WJMZU'><form id='WJMZU'><ins id='WJMZU'></ins><ul id='WJMZU'></ul><sub id='WJMZU'></sub></form><legend id='WJMZU'></legend><bdo id='WJMZU'><pre id='WJMZU'><center id='WJMZU'></center></pre></bdo></b><th id='WJMZU'></th></span></q></dt></tr></i><div id='WJMZU'><tfoot id='WJMZU'></tfoot><dl id='WJMZU'><fieldset id='WJMZU'></fieldset></dl></div>

  • <legend id='WJMZU'><style id='WJMZU'><dir id='WJMZU'><q id='WJMZU'></q></dir></style></legend><tfoot id='WJMZU'></tfoot>

          <bdo id='WJMZU'></bdo><ul id='WJMZU'></ul>

        Spring Data Rest:未调用 RepositoryEventHandler 方法

        时间:2024-08-24

            <tfoot id='Bo9Ok'></tfoot>
              <bdo id='Bo9Ok'></bdo><ul id='Bo9Ok'></ul>
              <legend id='Bo9Ok'><style id='Bo9Ok'><dir id='Bo9Ok'><q id='Bo9Ok'></q></dir></style></legend>

                  <tbody id='Bo9Ok'></tbody>

                • <small id='Bo9Ok'></small><noframes id='Bo9Ok'>

                  <i id='Bo9Ok'><tr id='Bo9Ok'><dt id='Bo9Ok'><q id='Bo9Ok'><span id='Bo9Ok'><b id='Bo9Ok'><form id='Bo9Ok'><ins id='Bo9Ok'></ins><ul id='Bo9Ok'></ul><sub id='Bo9Ok'></sub></form><legend id='Bo9Ok'></legend><bdo id='Bo9Ok'><pre id='Bo9Ok'><center id='Bo9Ok'></center></pre></bdo></b><th id='Bo9Ok'></th></span></q></dt></tr></i><div id='Bo9Ok'><tfoot id='Bo9Ok'></tfoot><dl id='Bo9Ok'><fieldset id='Bo9Ok'></fieldset></dl></div>
                  本文介绍了Spring Data Rest:未调用 RepositoryEventHandler 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试按照 Spring Data REST 文档 到如下所示的 REST 存储库:

                  I am trying to add a RepositoryEventHandler as described on Spring Data REST documentation to the REST repository shown below:

                  @RepositoryRestResource(collectionResourceRel = "agents", path = "/agents")
                  public interface AgentRepository extends CrudRepository<Agent, Long> {
                      // no implementation required; Spring Data will create a concrete Repository
                  }
                  

                  我创建了一个 AgentEventHandler:

                  I created an AgentEventHandler:

                  @Component
                  @RepositoryEventHandler(Agent.class)
                  public class AgentEventHandler {
                  
                      /**
                       * Called before {@link Agent} is persisted 
                       * 
                       * @param agent
                       */
                      @HandleBeforeSave
                      public void handleBeforeSave(Agent agent) {
                  
                          System.out.println("Saving Agent " + agent.toString());
                  
                      }
                  }
                  

                  并在@Configuration 组件中声明它:

                  and declared it in a @Configuration component:

                  @Configuration
                  public class RepositoryConfiguration {
                  
                      /**
                       * Declare an instance of the {@link AgentEventHandler}
                       *
                       * @return
                       */
                      @Bean
                      AgentEventHandler agentEvenHandler() {
                  
                          return new AgentEventHandler();
                      }
                  }
                  

                  当我发布到 REST 资源时,实体被持久化,但方法 handleBeforeSave 永远不会被调用.我错过了什么?

                  When I am POSTing to the REST resource, the Entity gets persisted but the method handleBeforeSave never gets invoked. What am I missing?

                  我正在使用:Spring Boot 1.1.5.RELEASE

                  I'm using: Spring Boot 1.1.5.RELEASE

                  推荐答案

                  有时明显的错误会被忽视.

                  Sometimes obvious mistakes go unnoticed.

                  POST - 使用 Spring Data REST 资源,发出 BeforeCreateEvent.要捕获此事件,必须使用 @HandleBeforeCreate 而不是 @HandleBeforeSave (后者在 PUT 和 PATCH HTTP 调用上调用)注释方法 handleBeforeSave.

                  POST-ing a Spring Data REST resource, emits a BeforeCreateEvent. To catch this event, the method handleBeforeSave must be annotated with @HandleBeforeCreate instead of @HandleBeforeSave (the latter gets invoked on PUT and PATCH HTTP calls).

                  测试在我的(清理后的)演示应用程序 现在.

                  Tests pass successfully on my (cleaned up) demo app now.

                  这篇关于Spring Data Rest:未调用 RepositoryEventHandler 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Org.Hibernate.AnnotationException:没有为实体指定标识符我的表中没有 id 下一篇:在 spring-data 项目中使用 @Version

                  相关文章

                  • <bdo id='ARae5'></bdo><ul id='ARae5'></ul>
                  1. <legend id='ARae5'><style id='ARae5'><dir id='ARae5'><q id='ARae5'></q></dir></style></legend>

                    <i id='ARae5'><tr id='ARae5'><dt id='ARae5'><q id='ARae5'><span id='ARae5'><b id='ARae5'><form id='ARae5'><ins id='ARae5'></ins><ul id='ARae5'></ul><sub id='ARae5'></sub></form><legend id='ARae5'></legend><bdo id='ARae5'><pre id='ARae5'><center id='ARae5'></center></pre></bdo></b><th id='ARae5'></th></span></q></dt></tr></i><div id='ARae5'><tfoot id='ARae5'></tfoot><dl id='ARae5'><fieldset id='ARae5'></fieldset></dl></div>
                  2. <tfoot id='ARae5'></tfoot>
                    1. <small id='ARae5'></small><noframes id='ARae5'>