diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java index 54f535b5162..ae2d620579c 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java @@ -4,6 +4,7 @@ import java.util.List; import javax.inject.Inject; +import org.apache.cloudstack.storage.datastore.db.DataStoreVO; import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver; import org.apache.cloudstack.storage.volume.Volume; import org.apache.cloudstack.storage.volume.db.VolumeDao; @@ -12,12 +13,14 @@ import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore { protected PrimaryDataStoreDriver driver; - protected List supportedDiskTypes; + protected DataStoreVO pdsv; + protected PrimaryDataStoreInfo pdsInfo; @Inject - VolumeDao volumeDao; - public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, List types) { + public VolumeDao volumeDao; + public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, DataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) { this.driver = driver; - this.supportedDiskTypes = types; + this.pdsv = pdsv; + this.pdsInfo = pdsInfo; } @Override @@ -46,7 +49,7 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore { return null; } - if (!this.getSupportedDiskTypes().contains(diskType)) { + if (!pdsInfo.isVolumeDiskTypeSupported(diskType)) { return null; } @@ -55,9 +58,4 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore { vol.update(); return vol; } - - @Override - public List getSupportedDiskTypes() { - return this.supportedDiskTypes; - } } diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java index e7ff49a05fd..3e06156e779 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java @@ -28,5 +28,4 @@ public interface PrimaryDataStore { List getVolumes(); boolean deleteVolume(long id); Volume createVolume(long id, VolumeDiskType diskType); - List getSupportedDiskTypes(); } diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfo.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfo.java new file mode 100644 index 00000000000..d30a5c8d221 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfo.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore; + +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; + +public interface PrimaryDataStoreInfo { + public boolean isHypervisorSupported(HypervisorType hypervisor); + public boolean isLocalStorageSupported(); + public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType); + public long getCapacity(); + public long getAvailableCapacity(); +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfoImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfoImpl.java new file mode 100644 index 00000000000..c453d33e93b --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfoImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore; + +import java.util.List; + +import org.apache.cloudstack.storage.datastore.db.DataStoreVO; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; + +public class PrimaryDataStoreInfoImpl implements PrimaryDataStoreInfo { + protected List supportedHypervs; + protected List supportedDiskTypes; + protected long caapcity; + protected long avail; + protected boolean localStorage; + + public PrimaryDataStoreInfoImpl(List hypers, List diskTypes, + long capacity, long avail, boolean localStorage) { + this.avail = avail; + this.caapcity = capacity; + this.localStorage = localStorage; + this.supportedDiskTypes = diskTypes; + this.supportedHypervs = hypers; + } + + @Override + public boolean isHypervisorSupported(HypervisorType hypervisor) { + return this.supportedHypervs.contains(hypervisor) ? true : false; + } + + @Override + public boolean isLocalStorageSupported() { + return this.localStorage; + } + + @Override + public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType) { + return this.supportedDiskTypes.contains(diskType) ? true : false; + } + + @Override + public long getCapacity() { + return this.caapcity; + } + + @Override + public long getAvailableCapacity() { + return this.avail; + } +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index 28744abf5d9..442949957ba 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -29,6 +29,7 @@ import java.util.Map; import javax.naming.ConfigurationException; import org.apache.cloudstack.storage.datastore.DataStoreStatus; +import org.springframework.stereotype.Component; import com.cloud.storage.StoragePoolDetailVO; import com.cloud.storage.dao.StoragePoolDetailsDao; @@ -44,6 +45,7 @@ import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.exception.CloudRuntimeException; +@Component public class PrimaryDataStoreDaoImpl extends GenericDaoBase implements PrimaryDataStoreDao { protected final SearchBuilder AllFieldSearch; protected final SearchBuilder DcPodSearch; diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDao.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDao.java new file mode 100644 index 00000000000..cebcacf3bdc --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDao.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.db; + +import com.cloud.utils.db.GenericDao; + +public interface PrimaryDataStoreProviderDao extends GenericDao { + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDaoImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDaoImpl.java new file mode 100644 index 00000000000..bd0571d6be0 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDaoImpl.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.db; + +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; + +@Component +class PrimaryDataStoreProviderDaoImpl extends GenericDaoBase implements PrimaryDataStoreProviderDao { + +} \ No newline at end of file diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderVO.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderVO.java new file mode 100644 index 00000000000..0ec6bf0f589 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderVO.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.db; + +public class PrimaryDataStoreProviderVO { + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java new file mode 100644 index 00000000000..fe4562c9102 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.lifecycle; + +import java.util.Map; + +import org.springframework.stereotype.Component; + +@Component +public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { + + @Override + public boolean registerDataStore(Map dsInfos) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean attach(long scope) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean dettach(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean unmanaged(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean maintain(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean cancelMaintain(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean deleteDataStore(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/PrimaryDataStoreLifeCycle.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/PrimaryDataStoreLifeCycle.java new file mode 100644 index 00000000000..2e41a62ee4a --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/PrimaryDataStoreLifeCycle.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.lifecycle; + +import java.util.Map; + +public interface PrimaryDataStoreLifeCycle { + public boolean registerDataStore(Map dsInfos); + public boolean attach(long scope); + public boolean dettach(long dataStoreId); + public boolean unmanaged(long dataStoreId); + public boolean maintain(long dataStoreId); + public boolean cancelMaintain(long dataStoreId); + public boolean deleteDataStore(long dataStoreId); +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java new file mode 100644 index 00000000000..dfa4663ad29 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.manager; + +import javax.inject.Inject; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao; +import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle; +import org.springframework.stereotype.Component; + +@Component +public class DefaultPrimaryDataStoreManagerImpl implements PrimaryDataStoreManager { + @Inject + PrimaryDataStoreProviderDao dataStoreProviderDao; + @Override + public PrimaryDataStore getPrimaryDataStore(long dataStoreId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java new file mode 100644 index 00000000000..b6ac34d3d76 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.manager; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle; + +public interface PrimaryDataStoreManager { + public PrimaryDataStore getPrimaryDataStore(long dataStoreId); + public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId); +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java index dd7e061519f..7ca9000d281 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java @@ -2,15 +2,41 @@ package org.apache.cloudstack.storage.datastore.provider; import javax.inject.Inject; +import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl; import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.PrimaryDataStoreInfo; +import org.apache.cloudstack.storage.datastore.db.DataStoreVO; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl; import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver; +import org.springframework.stereotype.Component; +import com.cloud.utils.component.ComponentInject; + +@Component public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider { + protected PrimaryDataStoreDriver driver; @Inject - public PrimaryDataStoreDriver driver; + public PrimaryDataStoreDao dataStoreDao; + + public DefaultPrimaryDatastoreProviderImpl() { + this.driver = new DefaultPrimaryDataStoreDriverImpl(); + } @Override - public PrimaryDataStore getDataStore(String dataStoreId) { + public PrimaryDataStore getDataStore(long dataStoreId) { + DataStoreVO dsv = dataStoreDao.findById(dataStoreId); + if (dsv == null) { + return null; + } + + PrimaryDataStore pds = new DefaultPrimaryDataStoreImpl(driver, dsv, null); + pds = ComponentInject.inject(pds); + return pds; + } + + @Override + public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId) { // TODO Auto-generated method stub return null; } diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java b/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java index 8a8d1012a21..a346d3206dc 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java +++ b/platform/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java @@ -1,7 +1,9 @@ package org.apache.cloudstack.storage.datastore.provider; import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.PrimaryDataStoreInfo; public interface PrimaryDataStoreProvider { - public PrimaryDataStore getDataStore(String dataStoreId); + public PrimaryDataStore getDataStore(long dataStoreId); + public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId); } diff --git a/platform/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java b/platform/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java index b8229e4b4e8..ca3a366687e 100644 --- a/platform/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java +++ b/platform/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java @@ -25,6 +25,7 @@ import java.util.LinkedList; import javax.inject.Inject; +import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl; import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl; import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider; import org.apache.cloudstack.storage.volume.VolumeMotionService; @@ -102,6 +103,10 @@ public class volumeServiceTest { @Test public void testStaticBean() { DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class); - assertNotNull(provider.driver); + assertNotNull(provider.dataStoreDao); + + DefaultPrimaryDataStoreImpl dpdsi = new DefaultPrimaryDataStoreImpl(null, null, null); + ComponentInject.inject(dpdsi); + assertNotNull(dpdsi.volumeDao); } } diff --git a/utils/src/com/cloud/utils/component/ComponentInject.java b/utils/src/com/cloud/utils/component/ComponentInject.java index 4578ea19e67..c88cd3f4c3c 100644 --- a/utils/src/com/cloud/utils/component/ComponentInject.java +++ b/utils/src/com/cloud/utils/component/ComponentInject.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Component; public class ComponentInject { private static AutowireCapableBeanFactory beanFactory; + @SuppressWarnings("unused") @Inject private void setbeanFactory(AutowireCapableBeanFactory bf) { ComponentInject.beanFactory = bf; @@ -17,4 +18,10 @@ public class ComponentInject { public static T inject(Class clazz) { return beanFactory.createBean(clazz); } + + public static T inject(T obj) { + beanFactory.autowireBean(obj); + beanFactory.initializeBean(obj, null); + return obj; + } }