Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Tags more
Archives
Today
Total
관리 메뉴

개발합니다

[Spring] Maven 스프링 프로젝트 구조 본문

Web/Spring

[Spring] Maven 스프링 프로젝트 구조

돈기법 2022. 3. 24. 14:48

src/main/java : 실제 자바 언어로 프로그래밍 기능 구현 부분 .java 파일 관리


src/main/resources : 여러 보조적인 역할들의 파일 - 빌드, 개발환경 관련 파일

  • 자원파일 관리 폴더로 스프링 설정 파일(XML) 또는 프로퍼티 파일 등이 관리됨.

 

pom.xml : 메이븐 설정파일로 메이븐은 라이브러리를 연결해주고, 빌드를 해주는 플랫폼이다.

스프링은 pom.xml에 의해서 명시해둔 필요한 라이브러리만 다운로드 해서 사용이 가능하다.

 

resources폴더에 생성한 .xml 파일을 통해 객체를 생성할 수 있다.
생성된 곳을 Spring Container, 생성된 객체를 bean이라고 칭함

 

[applicationContext.xml]

<?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.xsd">
		
	<bean id="tWalk" class="testProject.TransportationWalk" />
</beans>

 


GenericXmlAppricationContext 를 통해 xml에 접근 한 후 getBean을 통해 사용할 객체를 가져온다.  

 

[MainClass.java]

import org.springframework.context.support.GenericXmlApplicationContext;

public class MainClass {

	public static void main(String[] args) {
    		//스프링 컨테이너 생성
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext("classpath:applicationContext.xml");

		//Bean 객체 생성
		TransportationWalk transportationWalk = ctx.getBean("tWalk", TransportationWalk.class);
		transportationWalk.move();

		//스프링 컨테이너 종료
		ctx.close();
	}

}