java - @Autowired可以多次装配一个被@Component修饰的类吗?
PHP中文网
PHP中文网 2017-04-18 09:33:24
0
2
255

我写了一个包装Ehcache的类EhcacheWrapper,加入多线程控制,代码如下

@service
public class EhcacheWrapper{
   public Element get(String cacheName, String key){......}
   public void put(String cacheName, String key, Object value){......}
   //多线程控制,代码略
}

我在一个controller中自动装配EhcacheWrapper,比如

public class GetLabelServiceImpl{
   @Autowired
   private EhcacheWrapper ehcacheWrapper;
   //代码略
}

我在其他controller中还能@Autowired EhcacheWrapper吗?

我觉得@Component默认的scope是singleton,只有一个实例。如果在两个类中都@Autowired EhcacheWrapper,是不是两个类都调用同一个bean呢?EhcacheWrapper有多线程控制,这样做是不是有什么问题?应该怎么处理比较好?

PHP中文网
PHP中文网

认证高级PHP讲师

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!