티스토리 뷰
아주 쉬운 스프링 Spring hello world 예제를 살펴보자
1. 자바프로젝트 생성
File -> New -> Project
Project name: HelloSpring
이렇게 만들면 Project Explorer에서는
HelloSpring > src 와 JRE System Library가 보일것이다.
2. 필요한 라이브러리 추가
HelloSpring 프로젝트 이름에서 마우스 우클릭 하여
Properties -> Java Build Path 에서 Library 탭에서 Add External JARS 버튼 클릭
spring 관런 jar 들 추가
그럼 Package Explorer에서 보면 Referenced Libraries가 생긴다.
3. 소스 코딩
패키지를 만든다. src 폴더에서 마우스 우클릭하여 New->Package 선택하여
Name에 com.tutorialspoint 라고 입력한다.
그리고 HelloWorld.java와 MainApp.java를 만든다.
만든 패키지에서 마우스 우클릭 하여 New->Class 선택한후
Name에 HelloWorld.java 입력한다.
그리고 아래처럼 코딩한다.
package com.tutorialspoint;
public class HelloWorld {
private String message;
public void setMessage(String message){
this.message = message;
}
public void getMessage(){
System.out.println("Your Message : " + message);
}
}
마찬가지로 만든 패키지에서 마우스 우클릭 하여 New->Class 선택한후
Name에 MainApp.java 입력한다.
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
4. Bean 구성파일 생성
<?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.tutorialspoint.HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
</beans>
5. 프로그램 실행
이클립스 IDE 라면 Ctrl + F11.
결과
Your Message : Hello World!
//출처: https://www.tutorialspoint.com/spring/spring_hello_world_example.htm
1. 자바프로젝트 생성
File -> New -> Project
Project name: HelloSpring
이렇게 만들면 Project Explorer에서는
HelloSpring > src 와 JRE System Library가 보일것이다.
2. 필요한 라이브러리 추가
HelloSpring 프로젝트 이름에서 마우스 우클릭 하여
Properties -> Java Build Path 에서 Library 탭에서 Add External JARS 버튼 클릭
spring 관런 jar 들 추가
그럼 Package Explorer에서 보면 Referenced Libraries가 생긴다.
3. 소스 코딩
패키지를 만든다. src 폴더에서 마우스 우클릭하여 New->Package 선택하여
Name에 com.tutorialspoint 라고 입력한다.
그리고 HelloWorld.java와 MainApp.java를 만든다.
만든 패키지에서 마우스 우클릭 하여 New->Class 선택한후
Name에 HelloWorld.java 입력한다.
그리고 아래처럼 코딩한다.
package com.tutorialspoint;
public class HelloWorld {
private String message;
public void setMessage(String message){
this.message = message;
}
public void getMessage(){
System.out.println("Your Message : " + message);
}
}
마찬가지로 만든 패키지에서 마우스 우클릭 하여 New->Class 선택한후
Name에 MainApp.java 입력한다.
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
4. Bean 구성파일 생성
<?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.tutorialspoint.HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
</beans>
5. 프로그램 실행
이클립스 IDE 라면 Ctrl + F11.
결과
Your Message : Hello World!
//출처: https://www.tutorialspoint.com/spring/spring_hello_world_example.htm
'스프링 프레임워크(Spring Framework)' 카테고리의 다른 글
[스프링] @RequestBody Server returned HTTP response code: 400 (0) | 2018.03.16 |
---|---|
[스프링] cannot be resolved to a type (0) | 2018.02.27 |
스프링 파일 업로드 (0) | 2017.12.05 |
스프링 크론탭 crontab 예약작업 배치파일 실행하는 방법 (0) | 2017.06.26 |
자바스크립트 변수명 및 html id name 을 반복변수를 사용해서 변수 이름 만드는 방법 (0) | 2017.06.07 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 자바 smtp
- 포인터
- EC
- ocajp
- JDBC
- XE3
- php
- Python
- C
- 오라클
- 프로씨
- proc
- 문자열
- 인포믹스
- webix
- XE
- ocjap
- 스크래핑
- 자바
- 파싱
- ocpjp
- 이클립스
- xe애드온
- esql
- 자바 셀레니움
- xe addon
- 파이썬
- KG
- C언어
- MySQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함