스프링군살없이세팅하기(The way to setting the Spring framework for web.)EunChul Shin
깔끔하게 스프링 프레임워크 세팅하는 것에 대한 이야기 입니다.
군살없이 프레임워크를 세팅한다는 의미와 이유, 그리고 스프링 기본 설정 및 설정들의 역할에 대해서 정리해 보았습니다.
This presentation is about Spring framework.
I want to talk about the way to setting the spring framework as tidy in this presentation.
spring.io 레퍼런스(sagan project)를 통해서 배우는 spring 개발사례에 대해서 발표하고 정리한 프레젠테이션입니다. 작년에 SpringOne에서 발표된 inside spring.io 내용과 저의 개인적인 분석을 통해서 내용을 정리했습니다.
'입문자' 분들을 대상으로 정리했기 때문에 가능한한 간결하고 직관적으로 내용들을 표현했으며 깊게 들어가는 내용들은 거의 생략을 하였습니다.
자세한 내용들을 원하시면 프레젠테이션 중간중간에 관련 link를 첨부하였으니 같이 보시면은 도움이 되실것 같습니다.
스프링군살없이세팅하기(The way to setting the Spring framework for web.)EunChul Shin
깔끔하게 스프링 프레임워크 세팅하는 것에 대한 이야기 입니다.
군살없이 프레임워크를 세팅한다는 의미와 이유, 그리고 스프링 기본 설정 및 설정들의 역할에 대해서 정리해 보았습니다.
This presentation is about Spring framework.
I want to talk about the way to setting the spring framework as tidy in this presentation.
spring.io 레퍼런스(sagan project)를 통해서 배우는 spring 개발사례에 대해서 발표하고 정리한 프레젠테이션입니다. 작년에 SpringOne에서 발표된 inside spring.io 내용과 저의 개인적인 분석을 통해서 내용을 정리했습니다.
'입문자' 분들을 대상으로 정리했기 때문에 가능한한 간결하고 직관적으로 내용들을 표현했으며 깊게 들어가는 내용들은 거의 생략을 하였습니다.
자세한 내용들을 원하시면 프레젠테이션 중간중간에 관련 link를 첨부하였으니 같이 보시면은 도움이 되실것 같습니다.
Adied 2014, 봄싹 세미나에서 발표한 `Resource Handling in Spring MVC`의 발표자료입니다.
주요 내용으로 Spring MVC에서 정적 자원(css, js, etc)을 다루는 방법을 다루고 있습니다.
데모 코드 : https://github.com/arawn/resource-handling-in-springmvc
제 14회 한국 자바 개발자 컨퍼런스의 커뮤니티 세션에서 공유한 `overview of spring4` 의 발표 자료
스프링 프레임워크는 2004년에 출시된 이후 지금까지 많은 변화를 겪어왔습니다. 기억에 남아 있는 굴직한 변화를 더듬어 보면 버전 2.0은 XML 네임스페이스와 AspectJ 지원, 버전 2.5부터 애노테이션을 활용한 프로그래밍 기능이 추가되었습니다. 그리고 버전 3.0으로 올라가며 Java 5+ 기반으로 코드 구조가 바뀌고 자바 코드 기반 설정 기능이 추가되었습니다. 2013년 12월 13일에 버전 4.0 발표이 발표되었습니다. 주목할 변화는 바로 Java 8 지원과 제거 대상(@Deprecated)으로 선언되었던 많은 클래스와 메소드들이 삭제되었다는 것입니다. 이 외에도 많은 변화가 있습니다. 이번 시간에는 조금 높은 곳에서 내려다보는 느낌으로 무엇이 추가되었고, 어떤게 바뀌었는지 살펴보려고 합니다.
예제코드 : https://github.com/arawn/overview-of-spring4
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files.
Adied 2014, 봄싹 세미나에서 발표한 `Resource Handling in Spring MVC`의 발표자료입니다.
주요 내용으로 Spring MVC에서 정적 자원(css, js, etc)을 다루는 방법을 다루고 있습니다.
데모 코드 : https://github.com/arawn/resource-handling-in-springmvc
제 14회 한국 자바 개발자 컨퍼런스의 커뮤니티 세션에서 공유한 `overview of spring4` 의 발표 자료
스프링 프레임워크는 2004년에 출시된 이후 지금까지 많은 변화를 겪어왔습니다. 기억에 남아 있는 굴직한 변화를 더듬어 보면 버전 2.0은 XML 네임스페이스와 AspectJ 지원, 버전 2.5부터 애노테이션을 활용한 프로그래밍 기능이 추가되었습니다. 그리고 버전 3.0으로 올라가며 Java 5+ 기반으로 코드 구조가 바뀌고 자바 코드 기반 설정 기능이 추가되었습니다. 2013년 12월 13일에 버전 4.0 발표이 발표되었습니다. 주목할 변화는 바로 Java 8 지원과 제거 대상(@Deprecated)으로 선언되었던 많은 클래스와 메소드들이 삭제되었다는 것입니다. 이 외에도 많은 변화가 있습니다. 이번 시간에는 조금 높은 곳에서 내려다보는 느낌으로 무엇이 추가되었고, 어떤게 바뀌었는지 살펴보려고 합니다.
예제코드 : https://github.com/arawn/overview-of-spring4
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files.
기본적인 프로젝트 스캐폴딩 도구로 빠른개발을 위한 스프링 프레임워크 서브 프로젝트 중에 하나인 Spring Boot를 사용하겠습니다. 스프링 부트는 Convention over Configuration개념을 적용하여 개발자가 처리해야 하는 반복적인 성격의 설정작업을 대신 수행하여 개발자의 수고를 덜어주는 기술입니다.
최근 개발 초기단계에서부터 코드작성을 하지는 않습니다. 처음부터 코드를 작성하면 나중에 소스 코드 덩치가 커지거나 협업을 해야 하거나 배포를 해야 할 때 관리상의 문제가 많이 생긴다는 것을 개발자들은 이미 경험으로 알고 있기 때문입니다. 그러한 이유로 코드를 작성하기 전에 먼저 코드, 리소스, 디펜던시, 연동환경 및 테스트를 거친 후 배포작업을 미리 염두에 두고 구조적으로 프로젝트를 구분하는 스캐폴딩 작업을 선행합니다.
프로젝트 관점에서 살펴보면 실제 코드를 작성하기 전에 해야 할 여러 설정 작업들이 도출 됩니다. 스프링부트는 여러 설정작업들 중 개발자를 대신해 관습을 적용하여 자동화 할 수 있는 부분들을 제공하는 기술로써, 개발자의 수고를 덜어 보다 빠른 개발이 진행될 수 있도록 해줍니다.
커빙의 Django, Celery, Azure Cloud, SNS 연동, 컨텐츠 수집 기술을 한눈에 볼 수 있도록 소개한 자료 입니다.
커빙을 처음 개발하면서 많은 어려움이 있었지만
많은 분들의 도움으로 좋은 결과를 얻을 수 있었답니다!
이에 다른 분들에게 조금이나마 도움이 되었으면 좋겠다는 마음으로 공유합니다 : )
커빙의 Django, Celery, Azure Cloud, SNS 연동, 컨텐츠 수집 기술을 한눈에 볼 수 있도록 소개한 자료 입니다.
커빙을 처음 개발하면서 많은 어려움이 있었고,
또 많은 분들의 도움으로 좋은 결과를 얻을 수 있었습니다.
조금 더 깊은 내용을 다뤘으면 하는 아쉬움이 있지만,
다른 분들에게 조금이나마 도움이 되었으면 좋겠네요!
2. 자기 소개
정성용
Spring camp 2014
bungubbang57@gmail.com
!
SK Planet (2012 ~ )
Commerce Platform팀
공채 1기
3. Spring Boot - Goal Spring camp 2014
・ 모든 스프링개발을 정말 빠르고 다양한방법으로 시작할수 있도록 한다.
・ 부트 그대로 바로 사용할수도, 자신의 목적에 맞춰 다양하게 활용할 수도
있게 한다.
・ 어플리케이션의 기능적 요소 뿐만 아니라 임베디드 서버, 시큐리티, 헬스
체크, 외부 설정 연계등 개발의 모든 사이클을 제공한다.
・ 설정을 위해 Code Generation을 하지 않으며, XML이 필요하지도
않다.
4. Spring Boot 특징 Spring camp 2014
1. 어플리케이션 로직에 집중 할 수 있도록 과감하게 모든 설정을 없애버렸다.
2. Bean 중심의 설계를 바꿔 놓았다.
・ 설정을 변경하기 위해 Bean을 선언 하는것 뿐만 아니라 Property로 원하는 부분만 변
경 가능하다.
3. 스프링 개발의 지침서가 될 수 있다.
・ 스프링 메인 개발자들이 어떤 프로젝트를 장려하는지 어떻게 설정하고 활용하는지 boot
소스를 보면서 많은 참고를 할 수 있다.
5. Spring Boot Spring camp 2014
누가 사용 하면 좋을까요?
- 스프링을 완전 처음 시작하시는 분
- Boot 라이브러리 소스를 직접 파헤쳐 볼 수 있으신 분
!
어떤 상황에서 사용 하면 좋을까요?
- 익숙하지 않는 Spring 모듈을 사용할때
- 스프링으로 시작하는 모든 프로젝트
- 소규모 프로젝트에만 적용가능한건 오해
- 빠르지만 무한한 확장성이 장점
6. Spring Boot Example Spring camp 2014
Spring MVC
Spring Data JPA
Thymeleaf
Logback
Junite
웹 프로젝트 시작하기
with @EnableAutoConfiguration
7. Example Spring camp 2014
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.2.RELEASE</version>
</parent>
Pom.xml
<dependencies>
<dependency> // 개별 dependency 선언
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependencies>
8. Example Spring camp 2014
Domain
People
Repository
PeopleRepository
Controller
PeopleApiController
ThymeLeafController
Boot
BootSampleApplication
9. Example Spring camp 2014
@Entity // 일반적인 JPA Entity 설정
public class People {
@Id
@GeneratedValue
private Integer id;
!
private String name;
private Integer age;
// Constructor, Getter, Setter …
}
10. Example Spring camp 2014
@Repository // 일반적인 JpaRepository 설정
public interface PeopleRepository
extends JpaRepository<People, Integer> {
}
11. Example Spring camp 2014
@RestController // 일반적인 Controller 설정
@RequestMapping(value = "people")
public class PeopleApiController {
!
@Autowired PeopleRepository peopleRepository;
!
@RequestMapping(method = RequestMethod.GET)
public List<People> peopleList() {
return peopleRepository.findAll();
}
// POST, PUT, DELETE
}
12. Example Spring camp 2014
@ComponentScan
@EnableAutoConfiguration // 단 하나의 Boot 설정 !
public class BootSampleApplication {
public static void main(String[] args) throws Exception {
SpringApplication
.run(BootSampleApplication.class, args);
}
}
14. Spring Boot Spring camp 2014
빌드 시스템 (Java 1.6+)
Gradle, Maven, Ant
핵심 기능
Core Features
SpringApplication | External Configuration | Profiles | Logging
Web Application
MVC | Embedded Containers
Working with data
SQL | NO-SQL
Testing
Overview | Boot Applications | Utils
Extending
Auto-configuration | @Conditions
15. Spring Boot Spring camp 2014
Property Configuration
1. @PropertySource 설정
2. Java system, OS properties
3. Command Line arguments
4. application.properties (YAML포함)
- 위치 : /config, classpath:, classpath:/config
- profile : application-{profile}.properties
!
우선순위
Command Line > System properties
> @PropertySource > application.properties
!
참고 링크
http://docs.spring.io/spring-boot/docs/current/reference/
htmlsingle/#common-application-properties
17. Spring Boot Spring camp 2014
Actuator
- 스프링 어플리케이션을 조작하거나 상태를 알게 해주는 starter
/autoconfig 자동 설정되거나 설정되지 않는 목록들과 그 이유들
/beans 어플리케이션에서 선언한 Bean 목록
/configprops Properties 로 선언된 목록들
/dump Thread dump
/env 시스템 환경 및 어플리케이션 환경 설정 목록
/health 어플리케이션 상태 체크
/info 어플리케이션 정보
/metrics 어플리케이션의 매트릭스 정보
/mappings 어플리케이션의 매핑 정보
/shutdown 어플리케이션 종료
/trace 어플리케이션 접속 정보
18. Spring Boot Spring camp 2014
Spring MVC
!
1. 기본 설정
- Bean : ContentNegotiatingViewResolver, BeanNameViewResolver,
HttpMessageConverters(JSON, XML) …
- filter : HiddenHttpMethodFilter, WebRequestTraceFilter …
2. Resource
- /static, /public, /resources, /META-INF/resources in classpath
- favicon.ico 도 기본 지원
3. View template지원
- Thymeleaf, freemarker, velocity, groovy-templates
- 기본 폴더 : classpath:/templates/
19. Spring Boot Spring camp 2014
Logging
!
1. Log4J와 Logback 지원
- spring-boot-start-log4j (Log4J)
- spring-boot-start-logging (Logback)
2. 기본적으로 rotating, 10Mb file size
3. spring-starter-web 는 기본적으로 Logback 지원
- temp/spring.log
- application.properties의 logging.path로 변경 가능
- logback.xml 설정 가능
- 기본이 INFO, --debug로 수정 가능
20. Spring Boot Spring camp 2014
Servlet Container
!
1. Embedded
- Tomcat7, Jetty
2. Properties 설정
-server.port
-server.address
-server.sessionTimeout
3. extends EmbeddedServletContainerCustomizer
4. @Bean EmbeddedServletContainerFactory
21. Spring Boot Spring camp 2014
Database
!
1. Embedded database support
- H2, HSQL, Derby (dependency에 추가만)
2. Properties 설정
spring.datasource.url=jdbc:sql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driverClassName=com.sql.driver
!
3. @Bean DataSource
22. Spring Boot Spring camp 2014
spring-data-jpa
1. Properties 설정
- spring.jpa.hibernate.ddl-auto: create-drop
- spring.jpa.generate-ddl: false
- spring.jpa.show-sql: true
!
2. 초기 데이터 설정
- import.sql, schema.sql
- flyway, Liquibase 지원
spring-data-mongo
- spring.data.mongodb.host=mongoserver
- spring.data.mongodb.port=27017
23. Spring Boot Spring camp 2014
Testing
!
1. spring-boot-starter-test
- scope: test
- MVC test, Junit, Hamcrest, Mockito
- @SpringApplicationConfiguration