# 简单总结

\[TOC]

## 笔记

spring boot 采用“习惯优于配置，简化了大量配置。 Spring Boot更多的是采用Java Config的方式，对Spring进行配置。 采用了spring-boot-start-actuator之后，直接以REST的方式，获取进程的运行期性能参数。![spring-boot-start-actuator](/files/-Lcei66uqwAvFkOWlxi2)

## 参考资料

[Spring Boot导入XML配置【从零开始学Spring Boot】](http://blog.csdn.net/linxingliang/article/details/52263727) [Spring Boot浅谈(是什么/能干什么/优点和不足) - CSDN博客](http://blog.csdn.net/fly_zhyu/article/details/76407830) [Spring MVC将异常映射到HTTP状态码 - CSDN博客](http://blog.csdn.net/Q_AN1314/article/details/51736357)

## 启动

To run that application, use the `java -jar` command,exit the application hit `ctrl-c` [spring-boot-offical-reference](http://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/htmlsingle/#getting-started-first-application-run)

### 后台运行

使用`ctrl+z` 或者加 `&`在命令后面可以切换到后台运行，使用`jobs`和`fg`命令管理后台任务 ​

后台运行命令： `java -jar spring-boot01-1.0-SNAPSHOT.jar > log.file 2>&1 &` 详解（[参考](https://app.yinxiang.com/shard/s9/nl/679699/eb8e1e11-f4d0-413c-8098-110924dde5e4/)）：

* `> log.file` 打印日志，也可以从项目配置文件里配置日志文件，默认只打印控制台
* `2>&1` 把错误输出（2） 重定向到标准输出（1）

### 命令行参数

[参考](http://blog.csdn.net/isea533/article/details/50281151) 通过Java -jar app.jar --name="Spring" --server.port=9090方式来传递参数。

参数用--xxx=xxx的形式传递。

配置到`application.properties`文件中的参数都可以从外部传入后覆盖

更多常见的应用属性请浏览[这里](http://docs.spring.io/spring-boot/docs/1.2.3.RELEASE/reference/html/common-application-properties.html)

可以通过SpringApplication.setAddCommandLineProperties(false)禁用命令行配置。

### 配置文件从外部配置

[参考](http://www.jb51.net/article/108670.htm)

1. 通过命令行来重写和配置环境变量，优先级最高，例如可以通过下面的命令来重写spring boot 内嵌tomcat的服务端口，注意“=”俩边不要有空格 `java -jar demo.jar --server.port=9000` 如果想要设置多个变量怎么办，可以已json的格式字符串来设置 `java -jar demo.jar --spring.application.json='{"foo":"bar"}'`
2. 只需将配置文件放置在jar同一目录下即可，或者在jar所在目录创建一个config目录，将配置文件放置在config目录下面也可。[参考](http://blog.csdn.net/wo541075754/article/details/52540455)

### 非web的项目

[Spring Boot非web应用程序实例](http://www.yiibai.com/spring-boot/non-web-application-example.html)

```java
import org.springframework.boot.CommandLineRunner;

@SpringBootApplication
public class SpringBootConsoleApplication implements CommandLineRunner {

    public static void main(String[] args) throws Exception {

        SpringApplication.run(SpringBootConsoleApplication.class, args);

    }

    //access command line arguments
    @Override
    public void run(String... args) throws Exception {
        //do something
    }
}
```

## 零散知识

* [当spring 容器初始化完成后执行某个方法](https://www.cnblogs.com/rollenholt/p/3612440.html)
* [@Bean在@Configuration和在@Component中的区别](http://blog.csdn.net/ttjxtjx/article/details/49866011)
* [Spring Boot使用HandlerInterceptorAdapter和WebMvcConfigurerAdapter](https://www.cnblogs.com/EasonJim/p/7727012.html)
* [SpringBoot初始教程之Servlet、Filter、Listener配置(七)](http://blog.csdn.net/king_is_everyone/article/details/53116744)
* 本地jar 服务器部署war
  * [Spring boot 项目发布war 本地调试jar 方法](http://blog.csdn.net/mimica247706624/article/details/60765730)
  * [springBoot 由jar包转换为war包](http://blog.csdn.net/hao134838/article/details/71436834)
  * [把spring-boot项目部署到tomcat容器中](http://blog.csdn.net/javahighness/article/details/52515226)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.rizon.top/springboot/jian-dan-zong-jie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
