0
我正在使用装饰器模式来装饰具有缓存服务类的服务类。在春天自动装饰装饰器
没有春天,我会如下注入它:
private IService is = new CachingService(new RoleService());
需要注意的是,与Decorator模式相一致,既CachingService
和RoleService
实现IService
接口。 CachingService
,作为IService
的装饰者有一个构造函数,它需要一个IService
参数。
有没有一种方法可以使用Spring注释来自动装配它?
在情况下,它会帮助,我想是这样的:
@Autowire(with=CachingService, constructor-arg-ref=RoleService)
private IService is;