我可以使用Aspect来切换EntityManager,服务和存储库吗?

时间:2016-01-28 01:16:49

标签: spring-mvc aop aspectj spring-annotations

我有两个EntityManagers,用于两个DataSource,包含两个服务,存储库和一些实体。

LocalContainerEntityManagerFactoryBean masterEntiryManager;
LocalContainerEntityManagerFactoryBean replicaEntiryManager;
...
MasterBrickRepository masterBrickRepository;
ReplicaBrickRepsoitory replicaBrickRepository;
...
MasterBrickService masterBrickService;
ReplicaBrickService replicaBrickService;
...
MasterBrcik masterBrick;
ReplicaBrick replicaBrick;

目前,我按如下方式实施CRUD:

masterBrickService.save(masterBrick);
replicaBrickService.findAll();

当实体数量增长时,这是非常困难的!我不确定AOP是否可以通过用户注释来处理?这是可能的,我该怎么做?

BrickService brickService;
...
Brcik brick;
...
@Master
brickService.save(brick);

@Replica
brickService.findAll();

0 个答案:

没有答案