I am following basic example in Spring. The program is about printing a message "Hello World".
My question is : Can I use a different name for the instance variable and local variable in the Hello World Entity class? When I use the same name it works fine. But when I chose instance variable name as message and local variable name as msg as shown below it gives an error.
The HelloWorld bean has a property (a field) named 'message', and a corresponding setter method, 'setMessage'. The property name in the XML file refers to the name of the property in the HelloWorld bean, which is 'message'; not to the name of the argument variable.
Spring looks at the XML and sees that you want to set a property named 'message', so it looks for the 'setMessage' method in the HelloWorld bean, and then calls it with the value specified in the XML file.
If you'd name the property 'msg' in the XML file, it would go looking for a 'setMsg' method, and then it finds that this does not exist and throws an exception.