์น ์๋ฒ๋ ํด๋ผ์ด์ธํธ(๋ธ๋ผ์ฐ์ )์ HTTP ์์ฒญ์ ๋ฐ์ ์ ์ ์ธ ๋ฆฌ์์ค๋ฅผ ์๋ตํ๋ ์๋ฒ
๐ "ํ์ผ ์๋น + ํธ๋ํฝ ์ฒ๋ฆฌ ๋ด๋น"
๋น์ฆ๋์ค ๋ก์ง์ ์คํํ๊ณ ๋์ ์ปจํ ์ธ ๋ฅผ ์์ฑํ๋ ์๋ฒ
๐ "์ ํ๋ฆฌ์ผ์ด์ ์คํ ์์ง"
Spring Boot ์์ฒด๋ ํ๋ ์์ํฌ
๊ทธ ์์ ํฌํจ๋ ํฐ์บฃ์ด ์๋ฒ ์ญํ ์ ํจ -> WAS
๐ ๋ฐ๋ก Apache๋ Nginx ์์ด๋ ์น ์ ํ๋ฆฌ์ผ์ด์ ์ด ๋์ํ๋ ์ด์ ์ด๊ธฐ๋ ํจ
Spring IoC ์ปจํ ์ด๋์ ์ํด ๊ด๋ฆฌ๋๋ ๊ฐ์ฒด๋ฅผ ์๋ฏธ
์ผ๋ฐ์ ์ธ Java ๊ฐ์ฒด(POJO)์ง๋ง, Spring์ด ์์ฑ, ์ด๊ธฐํ, ์์กด์ฑ ์ฃผ์ , ์๋ฉธ ๋ฑ์ ์ฑ ์์ง๋ค๋ ์ ์์ ํน๋ณํ ๊ด๋ฆฌ ๋์์ด ๋จ
๐ ์ฝ๊ฒ ๋งํด, Spring์ ๋ฑ๋ก๋ ๊ฐ์ฒด๋ฅผ Bean์ด๋ผ๊ณ ๋ถ๋ฅด๋ ๊ฒ
Spring์ ๋ค์๊ณผ ๊ฐ์ ๊ฐ์ฒด๋ฅผ Bean์ผ๋ก ๊ด๋ฆฌํ ์ ์์:
@Controller, @Service, @Repository๊ฐ ๋ถ์ ํด๋์ค ์ธ์คํด์ค@Bean ๋ฉ์๋๊ฐ ์์ฑํ๋(return) ๊ฐ์ฒด<bean>์ผ๋ก ๋ฑ๋ก๋ ๊ฐ์ฒด์ฆ, ์ฐ๋ฆฌ๊ฐ ์คํ๋ฆฐํธ ๋ฏธ์ ์์ ๋ค๋ฃจ์๋ Service์ Repository ๋ฑ์ด ๋ชจ๋ Bean์ผ๋ก ๊ด๋ฆฌ๋ ๊ฒ
ํด๋์ค ์์ ์ด๋ ธํ ์ด์ ์ ๋ถ์ฌ ๋๋ฉด, Spring์ด ์ปดํฌ๋ํธ ์ค์บ(Component Scan)์ ํตํด ์๋์ผ๋ก Bean์ผ๋ก ๋ฑ๋กํจ
๐ ์ฅ์
๐ ๋จ์
์ค์ ํด๋์ค์์ ๋ฉ์๋๋ฅผ ํตํด ์ง์ Bean์ ๋ฑ๋ก
@Configuration
public class AppConfig {
@Bean
public UserService userService() {
return new UserService();
}
}
๐ ์ฅ์
๐ ๋จ์
๋ค๋ฅธ ์ค์ ํด๋์ค๋ฅผ ํ์ฌ ์ค์ ์ ํฌํจ์ํด
@Configuration
@Import(AppConfig.class)
public class MainConfig {
}
๐ ์ฅ์
๐ ๋จ์
XML ํ์ผ์ Bean์ ์ ์
<bean id="userService" class="com.example.UserService"/>
๐ ์ฅ์
๐ ๋จ์
๐ Spring Boot์์๋ ๊ฑฐ์ ์ฐ์ด์ง ์๋ ๋ฐฉ์
Bean์ ์ง์ ๋ง๋ค์ง ์๊ณ ,Bean ์์ฑ ์ฑ ์์ ๋ค๋ฅธ ๊ฐ์ฒด์ ์์
public class MyFactoryBean implements FactoryBean<MyObject> {
}
๐ ์ฅ์
๐ ๋จ์
ํ๊ฒฝ์ด๋ ์ค์ ๊ฐ์ ๋ฐ๋ผ Bean์ ์ ํ์ ์ผ๋ก ๋ฑ๋ก
@Profile("dev")
@Bean
public DataSource devDataSource() {
...
}
๐ ์ฅ์
๐ ๋จ์