1111// Unless required by applicable law or agreed to in writing,
1212// software distributed under the License is distributed on an
1313// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14- // KIND, either express or implied. See the License for the
14+ // KIND, either express or implied. See the License for the
1515// specific language governing permissions and limitations
1616// under the License.
1717package com .cloud .hypervisor .vmware .resource ;
1818
19+ import javax .annotation .PostConstruct ;
20+ import javax .inject .Inject ;
21+
1922import org .apache .log4j .Logger ;
23+ import org .springframework .stereotype .Component ;
2024
2125import com .cloud .hypervisor .vmware .manager .VmwareManager ;
2226import com .cloud .hypervisor .vmware .manager .VmwareManagerImpl ;
2529import com .cloud .utils .component .ComponentContext ;
2630
2731import com .vmware .apputils .version .ExtendedAppUtil ;
28-
32+ @ Component
2933public class VmwareContextFactory {
30-
34+
3135 private static final Logger s_logger = Logger .getLogger (VmwareContextFactory .class );
32-
36+
3337 private static volatile int s_seq = 1 ;
3438 private static VmwareManager s_vmwareMgr ;
35-
39+
40+ @ Inject VmwareManager _vmwareMgr ;
41+
3642 static {
3743 // skip certificate check
3844 System .setProperty ("axis.socketSecureFactory" , "org.apache.axis.components.net.SunFakeTrustSocketFactory" );
39- s_vmwareMgr = ComponentContext .inject (VmwareManagerImpl .class );
45+ //s_vmwareMgr = ComponentContext.inject(VmwareManagerImpl.class);
46+ }
47+
48+ @ PostConstruct
49+ void init () {
50+ s_vmwareMgr = _vmwareMgr ;
4051 }
4152
4253 public static VmwareContext create (String vCenterAddress , String vCenterUserName , String vCenterPassword ) throws Exception {
@@ -49,13 +60,13 @@ public static VmwareContext create(String vCenterAddress, String vCenterUserName
4960
5061 if (s_logger .isDebugEnabled ())
5162 s_logger .debug ("initialize VmwareContext. url: " + serviceUrl + ", username: " + vCenterUserName + ", password: " + StringUtils .getMaskedPasswordForDisplay (vCenterPassword ));
52-
63+
5364 ExtendedAppUtil appUtil = ExtendedAppUtil .initialize (vCenterAddress + "-" + s_seq ++, params );
54-
65+
5566 appUtil .connect ();
5667 VmwareContext context = new VmwareContext (appUtil , vCenterAddress );
5768 context .registerStockObject (VmwareManager .CONTEXT_STOCK_NAME , s_vmwareMgr );
58-
69+
5970 context .registerStockObject ("serviceconsole" , s_vmwareMgr .getServiceConsolePortGroupName ());
6071 context .registerStockObject ("manageportgroup" , s_vmwareMgr .getManagementPortGroupName ());
6172
0 commit comments