2012년 11월 21일 수요일

Invalid bean definition in Spring & VMwaer PowerCli

Today, I'd like to talk about two things. 

1. Same spring Error: Invalid bean definition 
The first is about the Spring error that caused due to the wrong bean definition. The message was the same with my last post.

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'WebServiceLocatordefined in file [C:\xxx\src\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\fdc-web\WEB-INF\classes\applicationContext.xml]: Could not resolve placeholder 'ws.userat org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
...

In conclusion, the symptom was because applicationContext-jdbc.xml was loaded twice. Look at my web.xml 
...
<context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
...


It is directive that loads all of the xml files which begin with "applicationContex". for example, applicationConext-a.xml and applicationContext-b.xml etc.. would be loaded when the web server starts. 



And I don't run the web server when I try testing my modules by run Junit Test. So, I need to add one line, my local applicationContext.xml to load additional xml config file.  

.....
<import resource="classpath:applicationContext-jdbc.xml"/>
.....

If I return to run and test modules with web server, I should have commented out this line. But I forgot that. 
<!-- <import resource="classpath:applicationContext-jdbc.xml"/> -->


2. VMware PowerCli 
VMware supports PowerCli which handles and managed VM and ESXi host by using Windows Powershell. 

It is able to download and install from here.
After run PowerCli, it looks like command prompt. (it has smaller window and it is not easy copy & past).

In my opinion, Powershell windows looks better and is easier than PowerCli.
It is also simple work for handling VMware as it work in powerCli.

Run Poweshell and type like the following:
PS C:\> Add-PSSnapin VMware.VimAutomation.core


# Connect to ESXi Server
PS C:\> Connect-VIServer -Server 192.168.20.162 -Protocol https -User root -Password **********

# Get a VM
PS C:\> $vm = Get-VM -Name swift-storage1 | select *

# Get an error while run get-harddisk 
PS C:\> Get-HardDisk -VM $vm
Get-HardDisk : Cannot bind parameter 'VM'. Cannot convert the "" value of type
"System.Management.Automation.PSCustomObject" to type  "VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine".
At line:1 char:17
+ Get-HardDisk -VM <<<<  $vm
    + CategoryInfo          : InvalidArgument: (:) [Get-HardDisk], ParameterBi
   ndingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat
   ion.ViCore.Cmdlets.Commands.VirtualDevice.GetHardDisk

I ran command with option " | select * ". 
This option made the VM recognize different object. Let's try Get-VM again without " | select * "

PS C:\> $vm2 = Get-VM -Name swift-storage1
PS C:\> $vm2.GetType()
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VirtualMachineImpl                       VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryIt...

# However, $vm is actually PSCustomObject, not VirtualMachine object.
PS C:\> $vm.GetType()
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PSCustomObject                           System.Object

# It returns results normally. 
PS C:\> Get-HardDisk -VM $vm2

CapacityGB  Persistence        Filename
----------    -----------        --------
100.000      Persistent          [datastore1] swift-storage1/swift-storage1.vmdk
100.000      Persistent          [datastore1] swift-storage1/swift-storage1_1.vmdk


댓글 없음:

댓글 쓰기