-
Notifications
You must be signed in to change notification settings - Fork 0
spring boot
- You can use Spring Boot to create Java applications that can be started by using java -jar or more traditional war deployments. (spring-boot-maven-plugin:repackage--letting you package executable jar or war archives and run an application “in-place”. To use it, you must use Maven 3.2 or later).
在插件executions中配置绑定插件目标repackage到生命周期的package phase(Your existing archive is enhanced by Spring Boot during the package phase,original archive会添加original suffix)。或者手动执行mvn package spring-boot:repackagekage`
- We also provide a command line tool that runs “spring scripts”. 见spring boot cli.
- mvn spring-boot:run. ( spring-boot为插件prefix, run为goal)
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
- inherit from the
spring-boot-starter-parent
project to obtain sensible defaults
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
包括:
- Java 1.8 as the default compiler level.
- UTF-8 source encoding.
- A Dependency Management section, inherited from the spring-boot-dependencies pom, that manages the versions of common dependencies. This dependency management lets you omit tags for those dependencies when used in your own pom.(参照
<dependcyMangement>
的用法) - Sensible resource filtering.
- Sensible plugin configuration (exec plugin, Git commit ID, and shade).
- Sensible resource filtering for application.properties and application.yml including profile-specific files (for example, application-dev.properties and application-dev.yml)(spring的placeholder ${..} maven的@..@ 可以覆盖parent的properties e.g. 覆盖spring data release train
- 中导入
spring-boot-dependencies
中的部分.如果需要覆盖,将需要覆盖的依赖定义在spring-boot-dependencies
之前.
<dependencyManagement>
<dependencies>
<!-- Override Spring Data release train provided by Spring Boot -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
建议Java-based配置,配置primary class类添加@Configuration
注解
@Import,@ImportResource导入其他配置类和xml配置
@EnableAutoConfiguration or @SpringbootApplication can enable auto-configuration based on the dependent jar
SpringBoot之@EnableAutoConfiguration原理及自定义扩展
导入了内置的配置类
@EnableAutoConfiguration 的exclude excludeName属性排除不想包含的配置类
or spring.autoconfigure.exclude属性
@SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \ -jar target/myapplication-0.0.1-SNAPSHOT.jar
hot-swapping spring-boot-devtools JRebel