SpringBoot (32) 썸네일형 리스트형 ch3 07. 의존성 관리와 설정의 자동화(2) 5. @SpringBootApplication - Spring Boot Application의 시작 클래스에 붙인다. - @SpringBootApplication = @Configuration(설정클래스) + @EnableAutoConfiguration(자동설정 가능) + @ComponentScan(자동 빈 스캔) @SpringBootApplication public class Main { public staitc void main(String[] args) { ApplicationContext ac = SpringApplication.run(Main.class, args); String[] beanDefinitionNames = ac.getBeanDefinitionNames(); Arrays.sort(.. ch3 06. 의존성 관리와 설정의 자동화(1) 1. 스타터(starter)란? - 여러 관련 라이브러리를 묶어서 패키지로 제공 - starter만 pom.xml에 추가하면, 관련 라이브러리가 자동으로 추가된다. org.springframework.boot spring-boot-starter-web 예를 들어 pom.xml파일에 이를 추가하고 reload project를 하면 관련 라이브러리가 자동 추가된다. 2. pom.xml이란? - Maven 기반 프로젝트의 설정 파일 - 프로젝트 기본 설정 정보, 의존 라이브러리, 설정 상속 정보를 지정 태그가 상속 정보를 지정하는 것. pom 파일의 부모 pom파일을 지정함. org.springframework.boot spring-boot-starter-parent 2.7.13 는 기본 설정 정보를 key .. ch3 05. Spring 애너테이션 4. 스프링 애너테이션 - @ComponentScan과 @Component - @ComponentScan으로 @Component를 자동 검색해서 빈으로 등록 - @Controller, @Service, @Repository, @ControllerAdvice의 메타 애너테이션 @Configuration // @ComponentScan("com.fastcampus.ch3") - basePackages 생략 // @ComponentScan(basePackages = {"com.fastcampus.ch3"}) - 패키지 지정 // @ComponentScan(basePackageClasses = AppConfig.class) - 클래스 지정 @ComponentScan // 이 애너테이션이 붙은 클래스의 패키지를 .. ch3 04. Bean과 ApplicationContext 1. Bean과 ApplicationContext - Bean : Spring Container가 관리하는 객체 - Spring container : Bean 저장소, Bean을 저장, 관리(생성, 소멸, 연결) 1. BeanFactory - Bean을 생성, 연결 등의 기본 기능을 정의(부모) 2. ApplicationContext - BeanFactory를 확장해서 여러 기능을 추가 정의(자식) Feature BeanFactory ApplicationContext Bean instantiation/wiring O O Integrated lifecycle management X O Automatic BeanPostProcessor registration X O Automatic BeanFactoryPo.. ch3 03. Spring DI의 원리(2) 3. 객체 컨테이너(ApplicationContext) 만들기 - 컨테이너는 객체 저장소 : Map을 저장소로 사용한다. AppContext ac = new AppContext(); Car car = (Car)ac.getBean("car"); Engine engine = (Engine)ac.getBean("engien"); class AppContext { Map map = new HashMap(); AppContext() { map.put("car", new SportsCar()); map.put("engine", new Engine()); } Object getBean(String id) {return map.get(id);} } 이렇게 하드코딩하면 변경에 불리하다. [AppConfig.java] c.. ch3 02. Java Reflection API 2. Java Reflection API란? - 클래스의 정보를 얻을 수 있는 기능을 제공. java.lang.reflect패키지. - 실행 중에 객체 생성, 메소드 호출 등을 가능하게 한다. (동적) * 정적 : 컴파일 때 결정 * 동적 : 실행중에 결정 - Reflection API를 이용한 예제 코드 Class carClass = Car.class; // Car 클래스의 Class 객체 얻기 -> 설계도 객체 Car car = (Car) carClass.newInstance(); // Car클래스의 객체를 생성 = Car car = new Car(); 보다 유연 Method[] methodArr = carClass.getDeclaredMethods(); // 클래스에 선언된 메소드 얻기 Field[.. ch3 01. Spring DI의 원리(1) 1. 변경에 유리한 코드(1) - 다형성, 추상화, factory method class Car {} class SportsCar extends Car {} class Truck extends Car {} SportsCar car = new SportsCar(); => Truck car = new Truck(); --> SportsCar() 클래스를 다른 클래스로 바꿀 때 두 군데를 고쳐야한다. Car car = new SportsCar(); => Car car = new Truck(); --> 코드를 이렇게 적으면 한 군데만 고치면 된다. (변경에 더 유리한 코드) - 더 변경에 유리한 코드로 만드려면, 메소드로 작성 Car car = getCar(); static Car getCar() { retur.. ch2 16. thymeleaf 사용하기 1. 타임리프(thymeleaf)란? - 자바 웹개발에 이상적인 '모던 서버 사이드 자바 템플릿 엔진' *.html로 타임리프 템플릿을 작성 -> 템플릿 엔진이 html 템플릿을 해석해서 html로 만들어서 보여준다. 여러 종류가 있지만 Spring boot에서는 thymeleaf가 기본으로 사용된다. (JSP보다 장점이 더 많다) - HTML과 유사해서 디자이너와 개발자간의 협업을 쉽게 해준다. - 확장성이 뛰어나며, 커스터마이징이 쉽다. - 다양한 도구와 확장 프로그램으로 구성된 에코 시스템 제공 http://www.thymeleaf.org/ecosystem.html Ecosystem - Thymeleaf Bootify.io https://bootify.io/ Bootify.io is a code g.. 이전 1 2 3 4 다음