当我创建一个@RepositoryRestController
对于一个实体,关联的@RepositoryEventHandler
方法不会通过 Spring Boot 1.4.0.M3(也包括 Spring Boot 1.3.5)在 Spring Data REST 中触发——这是一个 bug,还是按设计?
我有一个Account
实体具有@RepositoryEventHandler
:
@Slf4j
@Component
@RepositoryEventHandler(Account.class)
public class AccountEventBridge {
@HandleBeforeCreate
public void handleBeforeCreate(Account account){
log.info("Before create " + account);
}
@HandleAfterCreate
public void handleAfterCreate(Account account){
log.info("Created " + account);
}
}
当我发布时它们应该触发:
curl -H "Content-Type: application/json" -X POST
-d '{"name":"aaa", "owner":{"email":"aaa@1010","password":"snap"}}'
http://localhost:8080/api/accounts
除非我添加一个@RepositoryRestController
:
@RepositoryRestController
public class AccountRespositoryRestController {
private final AccountRepository repository;
@Autowired
public AccountRespositoryRestController(AccountRepository repository) {
this.repository = repository;
}
@RequestMapping(method = RequestMethod.POST,value = "/accounts")
public @ResponseBody PersistentEntityResource post(
@RequestBody Account account,
PersistentEntityResourceAssembler assembler) {
// ...
Account entity = this.repository.save(account);
return assembler.toResource(entity);
}
}
当我注释掉@RepositoryRestController
注释,将@RepositoryEventHandler
方法再次触发。
看起来这些应该独立运行,因为它们在 Spring Data REST 中操作两个不同的概念层——或者我误解了什么?
如果这是故意的,那就很不幸了——我必须实现所有 HTTP 方法来为任何具有以下属性的实体创建事件:@RepositoryRestController
。这真的是意图吗?