I have given above bean definition in spring xml file and get its instance in a following way:
Now I want to change the attribute "hours" value from 10 to 11 in the spring context file so that next time when I get the bean instance the value of hour field is 11 not 10.
currently inspite of changing it is returning 10 since the context file in which bean is defined has already been loaded and to get the instance with updated value I have to restart the entire application.
Is there any way so that I get the instance with the updated value?
In general, there wouldn't be a need to reload the configuration after ApplicationContext startup. However, there is a refresh() method you can call on an ApplicationContext, I don't recall the exact interface that method is defined, but there is one.
You see the line
ApplicationContext context = new ClassPathXmlApplicationContext("config-file.xml");
reads in the configuration and immediately creates Java objects to represent the xml, once that is done the xml is no longer read or used. So you would have to tell Spring to re-read it.
You can always use Spring JMX and expose that property as an MBean attribute that you can go through a JMX console like jconsole, which comes with the JDK, go to that mbean at runtime and change the value. This will not change the xml, but will change the bean in the Spring container to now have that new value at runtime.