static : 정적파일 (html, css ..)
template : 동적파일 (jsp, thymeleaf ..)
@SpringBootApplication = @SpringBootConfiguration + @ComponentScan + @EnableAutoConfiguration
클래스는 configuration용 클래스
@componentScan이 붙은 클래스가 위치해있는 현재 패키지 기준으로 그 아래 패키지를 찾아 스프링 빈으로 등록. @ComponentScan이 있는 클래스 하위의 패키지에 모든 자바파일을 생성
스프링 프레임워크에서 많이 쓰이는 스프링 bean들을 자동적으로 컨테이너에 등록
spring-boot-autoconfigure-2.1.1.RELEASE.jar\META-INF\spring.factoies org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
아래 @Configuration 있는 클래스를 모두 Load
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
...
war는 무조건 톰캣에 배포해야한다. 스프링부트는 jar로 배포가 가능한데 jsp로 작성해면 실행이 안된다.
비동기 통신
server.port=8000
scope이 테스트인 디펜던시는 모두 test 폴더 아래에서만 작성해야 한다.
<scope>test<scope>
모든 버전 관리
pom.xml
<properties>
<java.version>1.8</java.version>
<spring.version>5.1.8.RELEASE</spring.version>
</properties>
@SpringBootApplication
가 존재하는 패키지 아래에 자바클래스를 만들어서 작성해야 한다. 스타팅 포인트가 되는데 내부적으로 @componentScan을 가지고 있어서 스캔을 하지 못할 수 있다.
@SpringBootApplication
public class MyspringbootApplication {
public static void main(String[] args) {
SpringApplication.run(MyspringbootApplication.class, args);
}
}
제어의 역전
빈의 제어권을 개발자에서 프레임워크가 가져감
IoC 컨테이너를 제공
dependency lookup
dependency injection
public static void main(String[] args) {
SpringApplication.run(MyspringbootApplication.class, args);
}
웹어플리케이션 타입 | 요소 |
---|---|
WebApplicationType.SERVLET | 동기적(서블렛) |
WebApplicationType.REACTIVE | 비동기적 |
WebApplicationType.NONE | x |
public static void main(String[] args) {
SpringApplication application = new SpringApplication(MyspringbootApplication.class); //스프링 어플리케이션 객체 생성
application.setWebApplicationType(WebApplicationType.SERVLET); //웹 어플리케이션 타입 결정
application.run(args);
}
application.property
bgpark.name="Byeonggil Park"
bgpark.age=${random.int(1,100)}
bgpark.fullName=${bgpark.name}
MyRunner.java
@Value("${bgpark.name}")
private String name;
@Value("${bgpark.age}")
private int age;
f12
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
javaee api
javaee의 특징은 모두 인터페이스로 되어있어 구현체가 없다. tmax,제우스나 IBM에서 오라클에게 인증을 받으면서 구현체를 만든다.
함수형 인터페이스
추상메소드 하나 가지고 있는 인터페이스
function say(arg) {
return value
}
(arg) => value
Thread th = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("익명클래스");
}
});
th.start();
Thread th02 = new Thread(() -> System.out.println("람다식 "));
Consumer
인자 하나만 받고 void하는 클래스
(arg) -> void
Supplier
인자 없이 객체 반환
() -> Exception
dependency 추가
Jackson 컨버터 dependency 추가
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.6</version>
</dependency>
UserController
@RequestMapping(value="/usersxml",produces = {"application/xml"})
public List<User> getUserXml(){
return userRepository.findAll();
}