Lecture 71 - Spring(1) 스프링 프레임워크 설치법,
Lecture 71 - Spring(1) 스프링 프레임워크 설치법,
베니지오 IT 월드
갬성개발러 Bennyziio 2019. 6. 27. 09:24
스프링 시작하기
위에 Spring Framework가 핵심이다.
Spring Framework 설치법
pom.xml에서 java 버전을 1.8로, Spring을 5.0.8로 바꿔준다
4.0.0 org.springframework.samples SpringEx02 0.0.1-SNAPSHOT 1.8 UTF-8 UTF-8 5.0.8.RELEASE 4.2.1.Final 1.0.13 1.7.5 4.11 org.springframework spring-context ${spring-framework.version} org.springframework spring-tx ${spring-framework.version} org.slf4j slf4j-api ${slf4j.version} compile ch.qos.logback logback-classic ${logback.version} runtime org.hibernate hibernate-entitymanager ${hibernate.version} org.springframework spring-test ${spring-framework.version} test junit junit ${junit.version} test
SpringEx01.spring1.HelloSpring
package spring1; public class HelloSpring { public void sayHello(String name) { System.out.println(name + "님 안녕하세요"); } }
SpringEx01.spring1.HelloSpringMain
package spring1; public class HelloSpringMain { public static void main(String[] args) { // TODO Auto-generated method stub // 객체의 생성 코드로 작성 HelloSpring helloSpring = new HelloSpring(); helloSpring.sayHello("홍길동"); } }
SpringEx01.spring2.context
SpringEx01.Spring2.HelloSpring
package spring2; public class HelloSpring { public HelloSpring() { System.out.println("생성자 호출"); } public void sayHello(String name) { // TODO Auto-generated method stub System.out.println(name + "님 안녕하세요"); } }
SpringEx01.Spring2.HelloSpringMain
package spring2; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; public class HelloSpringMain { public static void main(String[] args) { // TODO Auto-generated method stub Resource resource = new ClassPathResource("spring2/context.xml"); BeanFactory beanFactory = new XmlBeanFactory(resource); HelloSpring helloSpring = (HelloSpring)beanFactory.getBean("helloSpring1"); helloSpring.sayHello("홍길동"); } }
from http://bennyziiolab.tistory.com/87 by ccl(S) rewrite - 2020-03-06 08:54:51
댓글
댓글 쓰기