Spring Framework Hello World ExampleHelloWorld.java
package com.jtc;
MainApp.java
public class HelloWorld { private String message; public void setMessage(String message){ this.message = message; } public void getMessage(){ System.out.println("Your Message : " + message); } }
package com.jtc;
Beans.xml
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MainApp { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); HelloWorld obj = (HelloWorld) context.getBean("helloWorld"); obj.getMessage(); } } <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="helloWorld" class="com.jtc.HelloWorld"> <property name="message" value="Hello World!"/> </bean> </beans>
commons-logging-1.1.1
OutPut
spring-aop-4.1.6.RELEASE spring-aspects-4.1.6.RELEASE spring-beans-4.1.6.RELEASE spring-context-4.1.6.RELEASE spring-context-support-4.1.6.RELEASE spring-core-4.1.6.RELEASE spring-expression-4.1.6.RELEASE spring-instrument-4.1.6.RELEASE spring-instrument-tomcat-4.1.6.RELEASE spring-jdbc-4.1.6.RELEASE spring-jms-4.1.6.RELEASE spring-messaging-4.1.6.RELEASE spring-orm-4.1.6.RELEASE spring-oxm-4.1.6.RELEASE spring-test-4.1.6.RELEASE spring-tx-4.1.6.RELEASE spring-web-4.1.6.RELEASE spring-webmvc-4.1.6.RELEASE spring-webmvc-portlet-4.1.6.RELEASE spring-websocket-4.1.6.RELEASE
Your Message : Hello World!
|