Apache Maven simplifies Java development by automating build tasks, standardizing directory layouts, and handling third-party dependencies seamlessly. When kickstarting your journey with Spring, generating and importing a simple Maven-based project into your IDE is the ideal first step.
In this step-by-step tutorial, you will learn how to set up a clean Spring Hello World project using Maven, configure the essential dependencies in pom.xml, import it into Eclipse, and execute your first Spring IoC container application.
1. Configure Maven Dependencies (pom.xml)
To enable core Spring features, add the spring-context artifact to your project's pom.xml:
HelloWorld helloWorldObj = (HelloWorld) context.getBean("helloBean"); System.out.println( "Got helloWorldObj from the ApplicationContext(Spring Container)");
helloWorldObj.printHello();
} }
Output
Mar 26, 2018 9:57:00 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5b37e0d2: startup date [Mon Mar 26 09:57:00 IST 2018]; root of context hierarchy
Mar 26, 2018 9:57:00 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [SpringBeans.xml]
setName(String name) method is called, Peter
Got helloWorldObj from the ApplicationContext(Spring Container)
Spring 5 : Hello World! Peter
No comments:
Post a Comment