简体   繁体   English

Spring Rest @HandleAfterCreate不触发

[英]Spring Rest @HandleAfterCreate doesn't fire

I've an handler class annotated with @RepositoryEventHandler and a method annotated with @HandleAfterCreate , like following: 我和注释的处理程序类@RepositoryEventHandler和带注释的方法@HandleAfterCreate ,像下面:

@Component
@RepositoryEventHandler(Test.class)
public class PropositionEventHandler {
    @HandleAfterCreate
    public void handleAfterCreate(final Proposition proposition) {
        System.out.println("Created");
    }
}

And a @RepositoryRestResource like this: 像这样的@RepositoryRestResource

@RepositoryRestResource(collectionResourceRel = "tests", path = "tests")
@CrossOrigin
public interface TestRepository extends PagingAndSortingRepository<Test, Long> {

}

So, when I send a json through Postman to my rest api, Spring inserts the record correctly into the database, but the event HandleAfterCreate never fires. 因此,当我通过Postman将json发送到我的rest api时, Spring HandleAfterCreate记录正确插入数据库中,但是事件HandleAfterCreate永远不会触发。

What am I missing here? 我在这里想念什么? Thanks. 谢谢。

You have to change type of your first parameter in method, because in your implementation it handles events from Proposition repository. 您必须在方法中更改第一个参数的类型,因为在您的实现中它将处理来自Proposition信息库的事件。 Spring uses first parameter to determine which event this handler can handle. Spring使用第一个参数来确定此处理程序可以处理的事件。

@Component
@RepositoryEventHandler
public class PropositionEventHandler {
    @HandleAfterCreate
    public void handleAfterCreate(final Test proposition) {
        System.out.println("Created");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM