我有以下类的StaticDataCachesServerBean,它由它的接口自动装配,即
@Autowired
private StaticDataCaches staticDataCaches;
在另一个班级
我已经在sdcAutoAssignmentRuleCache
类的init方法中创建了StaticDataCachesServerBean
的实例。根据我的理解,如果带有sdcAutoAssignmentRuleCache
的注释@Bean
不会产生任何影响,因为实例已经创建,并且在调用方法时返回相同的内容。
我的理解是否正确?
如果我不使用sdcAutoAssignmentRuleCache()
注释@Bean
方法,如果我使用@Bean
进行注释会怎样?
@Configuration
public class StaticDataCachesServerBean implements StaticDataCaches {
@Autowired
private CerebrumApplication cerebrumApplication;
private SdcUserCache sdcUserCache;
private SdcAutoAssignmentRuleCache sdcAutoAssignmentRuleCache;
@Override
public void init() {
sdcUserCache = new SdcUserCacheImpl(
new CacheUserProviderImpl(cerebrumApplication.getCacheProvider()));
sdcAutoAssignmentRuleCache= new SdcAutoAssignmentRuleCacheImpl(
new CacheSdcAutoAssignmentRuleProviderImpl(cerebrumApplication.getCacheProvider()));
}
@Bean
@Override
public SdcAutoAssignmentRuleCache sdcAutoAssignmentRuleCache() {
return sdcAutoAssignmentRuleCache;
}
}