我写了一个@interface
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface WriteToMap {
}
尊重
@Aspect
@Configuration
public class WriteToMapAspect {
@Autowired
private SingletonBuffer singletonBuffer;
@AfterReturning(value = "@annotation(writeToMap)", returning = "data")
public void processExecutionTime(WriteToMap writeToMap, Object data){
singletonBuffer.putToMap("key", data); // I am facing issue here how to get key
}
以下是我的存储库方法,其中已注释@WriteToMap
部门仓库
@Repository
public interface DepartmentRepository extends CrudRepository<DepartmentEntity, Long> {
@Override
@WriteToMap
<S extends DepartmentEntity> S save(S entity);
}
分支仓库
@Repository
public interface BranchRepository extends CrudRepository<BranchEntity, Long> {
@Override
@WriteToMap
<S extends BranchEntity> S save(S entity);
}
CategoryRepo
@Repository
public interface CategoryRepository extends CrudRepository<CategoryEntity, Long> {
@Override
@WriteToMap
<S extends CategoryEntity> S save(S entity);
}
服务
@Override
@Transactional
public DepartmentBo save(DepartmentBo departmentBo) {
departmentRepository.save(departmentBo.toEntity())
branchRepository.save(departmentBo.getBranch().toEntity())
categoryRepository.save(departmentBo.getCategory().toEntity())
return departmentBo;
}
我的问题是,当事务开始时,我想生成/获取唯一的密钥(不可共享的跨多个事务,但在事务范围内的调用方面可共享),直到事务完成为止。我要在这里设置的键
singletonBuffer.putToMap("key", data); // I am facing issue here how to get key
注意:putToMap基本上是基于键(即Map<String,List<Object>>