spring boot 文档学习笔记day02
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
上一篇: python聚类算法选择方法实例
推荐阅读
-
spring框架学习笔记1:搭建测试
-
韩顺平_PHP软件工程师玩转算法公开课(第一季)01_算法重要性_五子棋算法_汉诺塔_回溯算法_学习笔记_源代码图解_PPT文档整理
-
Spring学习笔记之RedisTemplate的配置与使用教程
-
超详细的Spring Boot入门笔记(总结)
-
Spring学习笔记之RedisTemplate的配置与使用教程
-
SpringBoot入坑笔记之spring-boot-starter-web 配置文件的使用
-
深入学习Spring Boot排查 @Transactional 引起的 NullPointerException问题
-
SpringBoot入坑笔记之spring-boot-starter-web 配置文件的使用
-
深入学习Spring Boot排查 @Transactional 引起的 NullPointerException问题
-
Spring学习笔记之bean生命周期