The directory structure 2.springboot
1. Basic Information
- static :保存所有的静态资源,css、js、img
- templates :保存所有的模版页面(springboot内嵌tomcat,默认不支持jsp)(官方推荐使用thymeleaf)
- application.properties/yml :用来保存各种配置信息的文件,修改springboot的默认值
2. Configure the information
== YML (YAML Is not Markup Language) a markup language, but not just markup language, it is data-centric, more suitable for the configuration file ==
server:
port: 8080
Using an array of yml
person:
- one
- two
- three
pserson: [one,two,three]
Want to call the value of the configuration file, you need to add some notes on the configuration class @ConfigurationProperties
@ConfigurationProperties(prefix = "person") //和配置文件中的信息绑定
== == import configuration file in the processor file pom
<dependency>
<groupId>maven.org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
The method can also be used @Value injection was added to this annotation on the property
== @ Validated check notes == @Email
@ConfigurationProperties | @Value | |
---|---|---|
Features | Batch injection configuration file attributes | One of the designated |
Loosely bound (loose syntax) | stand by | not support |
Game | not support | stand by |
JSR303 data check | stand by | not support |
Complex type package | stand by | not support |
3.@PropertySource&@ImportResource
@PropertySource (value = { "classpath: a.properties"}) profile load developed
@ImportResource (locations = { "classpath: a.xml"}) introduction of spring profile, so that the contents inside the commencement
4. configuration class
@Configuration
public class MyAppConfig {
@Bean //默认id是方法名
public HelloService helloService(){
return new HelloService();
}
}
5.profile
When enabled multi-profile file spring.profiles.active join in on only the configuration file =? (Extended multi-profile file)
yml way to support multiple document block
server: port: 8080 spring: profiles: active: dev --- server: port: 8081 spring: profiles: dev --- server: port: 8082 spring: profiles: prod
You can use the command line in the manner specified