포스코DX X 비트교육센터 6기 - Spring Boot


Bootstrap

어떤 일을 하기 전에 모든 준비를 마치는 것

-> Spring Boot : Application이 실행되기 전까지의 모든 준비를 자동으로 마치게 해주는 library, tool ( 비즈니스 구현, 상투적이고 반복적인 것을 자동으로 설정 )

  1. Auto Configuration(자동설정) : 추가적으로 미세설정은 필수

  2. Starter Dependency(스타터 의존성)

image

실습

springboot-practices |– springboot-ex |– springboot-helloworld |– springboot-myapplication |– springboot-myweb

  • 폴더 추가

image

  • .metadata 폴더 있는 image

image

image

image

image

image

image

image

깃에 올리기

image

https://start.spring.io/

@SpringbootConfiguration

package ex02;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootConfiguration
public class MyApplication {
	
	@Bean
	public MyComponent myComponent() {
		return new MyComponent();
	}
	
	public static void main(String[] args) {
		try(ConfigurableApplicationContext ac = SpringApplication.run(MyApplication.class, args)){}
		
	}

}

package ex02;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * Spring Test Integration
 * 
 * Success
 * @SpringbootConfiguration 을 달고 있는 설정 클래스를 통해 스캔 했다.
 * 
**/

@SpringBootTest
public class MyApplicationTest02 {

	@Autowired
	private MyComponent myComponenet;
	
	@Test
	public void myComponentNotNull() {
		assertNotNull(myComponenet);
	}
}

@ComponentScan : 하부 패키지를 스캔

package ex03;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import ex03.component.MyComponent;

@SpringBootConfiguration
@ComponentScan
public class MyApplication {
	
	@Bean
	public MyComponent myComponent() {
		return new MyComponent();
	}
	
	public static void main(String[] args) {
		try(ConfigurableApplicationContext ac = SpringApplication.run(MyApplication.class, args)){}
		
	}

}
package ex03;



import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import ex03.component.MyComponent;

/**
 * Spring Test Integration
 * 
 * Success
 * @SpringbootConfiguration 을 달고 있는 설정 클래스를 통해 스캔 했다.
 * 
**/

@SpringBootTest
public class MyApplicationTest {

	@Autowired
	private MyComponent myComponenet;
	
	@Test
	public void myComponentNotNull() {
		assertNotNull(myComponenet);
	}
}

@SpringBootApplication

package ex04;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import ex03.component.MyComponent;

/**
 * @SpringBootApplication 메타 어노테이션
 * 
 *  + @SpringBootConfiguration: cf) ex01, ex02
 *  + @ComponentScan: ex04, 하부 패키지를 스캔한다. cf)ex03 
 *  + @EnableAutoConfiguration:
 *  	1. MVC, AOP, Security, JPA 등을 자동으로 설정
 *  	2. 발견된 Starter Dependency(Library) 기반으로 설정 (관례를 따르는 default 설정)
 *  	3. + application.properties나 application.yml 안의 미세 설정 (필수)
 * **/
@SpringBootApplication
public class MyApplication {
	
	@Bean
	public MyComponent myComponent() {
		return new MyComponent();
	}
	
	public static void main(String[] args) {
		try(ConfigurableApplicationContext ac = SpringApplication.run(MyApplication.class, args)){}
		
	}

}