我有一个名为Drives的类,它动态实例化FsAccess bean 我有一个名为ServersAccessService的服务类,它找到FsAccess bean并使用@autowired将它们存储在地图中。有没有办法让驱动程序完成实例化FsAccess bean后服务类启动@autowired?
服务类:
public class ServersAccessService implements DisposableBean {
protected static final Log log = LogFactory.getLog(ServersAccessService.class);
protected static Map<String, FsAccess> servers = new HashMap<String, FsAccess>();
I
protected Map<String, FsAccess> restrictedServers = new HashMap<String, FsAccess>();
protected boolean isInitialized = false;
protected static Map<String, DrivesCategory> drivesCategories = new HashMap<String, DrivesCategory>();
@Autowired
public void setServers(List<FsAccess> servers) {
for(FsAccess server: servers) {
this.servers.put(server.getDriveName(), server);
}
}
驱动课程:
MyBeanFactory mbf = new MyBeanFactory();
//loop through each drive in driveList
for(String name:driveList)
{
String fullUri = "smb://naz-fs3/home/"+name;
String icon = "/esup-portlet-stockage/img/drives/root.png";
VfsAccessImpl drive = mbf.createInstance();
//Set attribute information
drive.setDriveName(name);
drive.setIcon(icon);
drive.setUri(fullUri);
drive.setContextToken(name);
}
答案 0 :(得分:0)
如果Drives
bean在初始化阶段实例化FsAccess
bean,您可以通过depends-on向ServersAccessService
声明Drives
bean的依赖关系} 豆。这会在Drives
bean初始化之前强制ServersAccessService
bean的初始化。
答案 1 :(得分:0)
我相信你想要的是让你的驱动器类成为一个@Configuration bean,并使返回一个使用@Bean注释的List的方法。这样弹簧容器就可以了解FsAccess列表,并且可以通过@Autowired进行注射。
编辑:
参考:http://blog.springsource.com/2006/11/28/a-java-configuration-option-for-spring/