본문 바로가기

Language/Java

[Spring] 스프링 프로젝트 생성

STS 설치하기
- STS(Spring Tool Suite)란?
  이클립스 기반 스프링 애플리케이션을 위한 개발 환경.
  스프링 프레임워크로 웹 개발을 하기 위해 필요.
 

Spring Tools 4 is the next generation of Spring tooling

Largely rebuilt from scratch, Spring Tools 4 provides world-class support for developing Spring-based enterprise applications, whether you prefer Eclipse, Visual Studio Code, or Theia IDE.

spring.io

 

기본 자바 프로젝트 생성

 

Maven Project 변환

 

Spring Project 변환

 

스프링 빈을 관리할 수 있는 xml 형식의 파일 생성

 

<bean id="car" class="model.domain.Car"/>

 

  • scope="singleton" (default가 싱글톤) : java 소스에서 `getBean()`으로 스프링 빈을 받아서 사용, 여러번 실행해도 동일한 Car 객체 반환

 

<bean id="car2" class="model.domain.Car" scope="prototype"/>

 

  • scope="prototype" : 개별 객체 필요시 설정, getBean() 호출 시점에 생성됨

 

<bean id="car3" class="model.domain.Car">
    <constructor-arg name="carName" value="encoreCar"/>
    <constructor-arg>
    	<value>10</value>
    </constructor-arg>
</bean>
  • constructor injection : 객체 생성시 멤버 변수값 초기화 하는 방법 - parameter가 있는 생성자 활

 

<bean id="car4" class="model.domain.Car">
    <property name="carName" value="encoreCar"/>
    <property name="carNumber" value="20"/>
</bean>
  • setter injection : 객체 생성시 멤버 변수값 초기화 하는 방법 - parameter가 있는 메소드 활용

 

 

스프링 빈의 의존성 관계도 확인 예시

'Language > Java' 카테고리의 다른 글

[Spring] 개념 정리  (0) 2021.10.07
JSP  (0) 2021.09.19
Servlet  (0) 2021.08.30
Apache Tomcat  (0) 2021.08.30
Lombok 라이브러리  (0) 2021.08.18