spring boot 文档学习笔记day02
2018-06-18 02:47:18来源:未知 阅读 ()
1. 启动报错,查看debug
$ java -jar myproject-0.0.1-SNAPSHOT.jar –debug
2.自定义banner
The banner that is printed on start up can be changed by adding a banner.txt
file to your classpath or by setting the spring.banner.location
property to the location of such a file. If the file has an encoding other than UTF-8, you can set spring.banner.charset
. In addition to a text file, you can also add a banner.gif
, banner.jpg
, or banner.png
image file to your classpath or set the spring.banner.image.location
property. Images are converted into an ASCII art representation and printed above any text banner.
3. 自定义SpringApplication
public static void main(String[] args) {
SpringApplication app = new SpringApplication(MySpringConfiguration.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
}
4. 获取运行参数
If you need to access the application arguments that were passed to SpringApplication.run(…
?)
, you can inject a org.springframework.boot.ApplicationArguments
bean. The ApplicationArguments
interface provides access to both the raw String[]
arguments as well as parsed option
and non-option
arguments, as shown in the following example:
import org.springframework.boot.*
import org.springframework.beans.factory.annotation.*
import org.springframework.stereotype.*
@Component
public class MyBean {
@Autowired
public MyBean(ApplicationArguments args) {
boolean debug = args.containsOption("debug");
List<String> files = args.getNonOptionArgs();
// if run with "--debug logfile.txt" debug=true, files=["logfile.txt"]
}
}
5.application.properties的读取顺序
SpringApplication loads properties from application.properties files in the following locations and adds them to the Spring Environment:
- A /config subdirectory of the current directory
- The current directory
- A classpath /config package
- The classpath root
The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).
6. 指定配置文件名和位置
The following example shows how to specify a different file name:
$ java -jar myproject.jar --spring.config.name=myproject
The following example shows how to specify two locations:
$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
7.@ConfigurationPropertie宽松的多种绑定,properties中推荐小写+中划线
- @ConfigurationProperties(prefix="acme.my-project.person")
public class OwnerProperties {
private String firstName;
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
In the preceding example, the following properties names can all be used:
acme.my-project.person.firstName |
Standard camel case syntax. |
acme.my-project.person.first-name |
Kebab case, which is recommended for use in .properties and .yml files. |
acme.my-project.person.first_name |
Underscore notation, which is an alternative format for use in .properties and .yml files. |
ACME_MYPROJECT_PERSON_FIRSTNAME |
Upper case format, which is recommended when using system environment variables. |
The prefix
value
for the annotation must
be in kebab case (lowercase and separated by -
, such as acme.my-project.person
).
8. profiles
Spring
Profiles provide a way to segregate parts of your application configuration and
make it be available only in certain environments. Any @Component
or @Configuration
can be marked with @Profile
to limit when it is loaded
You can use a spring.profiles.active
Environment
property to specify which profiles are active:spring.profiles.active=dev,hsqldb
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- Spring系列.ApplicationContext接口 2020-06-11
- springboot2配置JavaMelody与springMVC配置JavaMelody 2020-06-11
- 给你一份超详细 Spring Boot 知识清单 2020-06-11
- SpringBoot 2.3 整合最新版 ShardingJdbc + Druid + MyBatis 2020-06-11
- 掌握SpringBoot-2.3的容器探针:实战篇 2020-06-11
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash