스프링부트springboot 이야기
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
단독실행가능한 스프링애플리케이션을 생성한다.
내장형 톰캣, 제티 혹은 언더토우를 내장(
WAR
파일로 배포할 경우에는 필요없음)
기본설정되어 있는 'starter' 컴포넌트들을 쉽게 추가
가능한 자동설정되어 있음
상용화에 필요한 통계, 상태 점검 및 외부설정을 제공
설정을 위한 XML 코드를 생성하거나 요구하지 않음
Application.java
확인
@SpringBootApplication
확인@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Configuration // JavaConfig
@EnableAutoConfiguration // 자동설정 활성화
@ComponentScan // 해당위치부터 컴포넌트 스캔 진행
public @interface SpringBootApplication {
/**
* Exclude specific auto-configuration classes such that they will never be applied.
* @return the classes to exclude
*/
Class<?>[] exclude() default {};
}
autoconfig 패키지 확인
@Conditional, @ConditionalOnBean, @ConditionalOnMissingBean, @ConditionalOnClass
build.gradle
- spring-boot-starter-data-jpa
starterspring.provides
: 스프링부트에 추가되는 컴포넌트 정의provides: spring-orm,hibernate-entity-manager,spring-data-jpa
h2database
spring-boot-starter-data-jpa
@Entity
와 Repository
기본사용디렉토리 | 의미 |
---|---|
src/main/java | Production Java source |
src/main/resources | Production resources |
src/test/java | Test Java source |
src/test/resources | Test resources |
@SpringBootApplication
선언된 클래스는 패키지 최상위에 위치한다.@ComponentScan
가 제대로 동작하려면 스프링부트애플리케이션클래스는 패키지 상단에 위치한다.com
+- innotree
+- myproject
+- Application.java
|
+- domain
| +- Customer.java
| +- CustomerRepository.java
|
+- service
| +- CustomerService.java
|
+- web
+- CustomerController.java
src/main/resources/templates
사용을 권장한다.org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
중에서private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" };
/META-INF/resources/
, /resources
, /static
, /public
경로를 기본탐색한다./WEB-INF/resources
의 경우, jar
파일로 배포할 경우에는 인식하지 않기때문에 사용하지 않도록 주의한다./static
디렉토리 사용을 권장한다..bowerrc
파일 작성{
"directory": "src/main/resources/static/bower_components",
"json": "bower.json"
}
bower.json
파일 작성: bower init
사용{
"name": "project-word-management",
"dependencies": {
"angular": "~1.4.3",
"angular-resource": "~1.4.3",
"bootstrap-css-only": "~3.2.0",
"requirejs": "~2.1.19"
},
"version": "0.0.1",
"homepage": "https://github.com/ihoneymon/project-word-management",
"authors": [
"ihoneymon <ihoneymon@gmail.com>"
],
"description": "프로젝트 용어 관리",
"moduleType": [
"amd",
"globals"
],
"keywords": [
"springboot",
"gradle",
"bower"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"src/main/resources/static/bower_components",
"test",
"tests"
]
}
build.gradle
task 정의task bowerInstall(type:Exec) {
inputs.files "bower.json"
commandLine "bower", "install"
}
$ gradle bowerInstall
를 프로젝트에서 실행하면 bower.json
에 선언된 의존성항목들이 추가된다.autoconfigure
에서 자동설정된 항목들에 대해서 외부 설정이 가능해진다.PropertySource
의 값, 속성 오버라이드 순서java:comp/env
.System.getProperties()
).RandomValuePropertySource
that only has properties in random.*
.application-{profile}.properties
and YAML variants)application-{profile}.properties
and YAML variants)application.properties
and YAML variants).application.properties
and YAML variants).@PropertySource
annotations on your @Configuration
classes.SpringApplication.setDefaultProperties
)./src/main/resources
에 위치한다./src/main/resources/application.properties
혹은 /src/main/resources/application.yml
@ConfigurationProperties
지원