• <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 方法

        Spring Data Rest: RepositoryEventHandler methods not invoked(Spring Data Rest:未调用 RepositoryEventHandler 方法)

            <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 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    • <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>

                              <tbody id='ARae5'></tbody>

                            <small id='ARae5'></small><noframes id='ARae5'>