Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hi Pankaj, I am new for Spring , I followed your above code with some changes, But i am getting Error : IOException parsing XML document from class path resource [CoreSpring/src/main/resources/Test.xml]; nested exception is java.io.FileNotFoundException: class path resource [CoreSpring/src/main/resources/Test.xml] cannot be opened because it does not exist at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341). I placed Bean XML into /CoreSpring/src/main/resources/Test.xml path But still getting same error.But when i tried without Maven it working good.Please help me. Class Code : public class InjectSimple { private String name; private int age; private int height; private float ageInSeconds; private boolean programmer; public static void main(String a[]) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( “/CoreSpring/src/main/resources/Test.xml”); InjectSimple simple=(InjectSimple) context.getBean(“sample”); System.out.println(simple); } //Setter and Getter Methods.
- Adarsha
Very nice explanation…I appreciate your efforts. Before that I read all above theoretically but u explain it with an example which is easily understandable to any one. thanks
- Nandu
nice article …earlier i was usnig xml base configuration…but after reading this article i moved my p[roject to pannotaion based configuration file…thanks (Y)
- Atmrakash Sharma
could use please explain @value annotation with an example using annotation based dependency injection
- mani
I think that the DIConfiguration.java is wrong on the “service” configuration. It says @Bean public MessageService getMessageService(){ return new EmailService(); } As java config uses the name of the method as id, it should be instead @Bean public MessageService service(){ return new EmailService(); } Then the MyApplication.java would have access to the service. On DIConfiguration.java you should decide if you need the TwitterService or EmailService. Unless I am missing something :)
- Ismael
Pankaj, you said that ‘Context objects are resource intensive, so we should close them when we are done with it’. What about WebApplicationContext, it is from org.springframework.web.context.support.WebApplicationContextUtils and do we neeed to close it since it does not have any close method?
- Andreas Papandreas