关于Spring Boot标签@的解析
//用来标注一个主程序类,说明这是一个SpringBoot程序
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args) {
//Spring 应用启动
SpringApplication.run(HelloWorldMainApplication.class, args);
}
}
@SpringBootApplication的作用:
标注在某个类上,说明是SpringBoot的主配置类,SpringBoot就应该运行这个类的main方法来启动应用
点开@SpringBootApplication
// Compiled from SpringBootApplication.java (version 1.8 : 52.0, no super bit)
@java.lang.annotation.Target(value={java.lang.annotation.ElementType.TYPE})
@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
@java.lang.annotation.Documented
@java.lang.annotation.Inherited
@org.springframework.boot.SpringBootConfiguration
@org.springframework.boot.autoconfigure.EnableAutoConfiguration
@org.springframework.context.annotation.ComponentScan(excludeFilters={@org.springframework.context.annotation.ComponentScan.Filter(type=org.springframework.context.annotation.FilterType.CUSTOM,
classes={org.springframework.boot.context.TypeExcludeFilter}),@org.springframework.context.annotation.ComponentScan.Filter(type=org.springframework.context.annotation.FilterType.CUSTOM,
classes={org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter})})
public abstract @interface org.springframework.boot.autoconfigure.SpringBootApplication extends java.lang.annotation.Annotation
发现@SpringBootApplication中又有这么多个注解,我们一一解析
@SpringBootConfiguration: SpringBoot的配置类上标注这个注解(配置类----配置文件)配置类也是容器中的一个组件
@EnableAutoConfiguration: 开启自动配置功能,将主配置类(@SpringBootApplication标注的类)的所在的包及下面所有子包里面的所有组件扫描到Spring容器中
Spring Boot配置文件解析
resources文件夹中目录结构
- static:保存所有的静态资源:js,css,images
- templates:保存所有的末班页面:(Spring Boot默认jar包使用嵌入式的Tomcat,默认不支持JSP页面),可以使用末班引擎(freemarker、thymeleaf)
- application.properties:Spring Boot应用的全局配置文件,有application.yml和application.properties两种形式,作用是修改Spring Boot配置的默认值
yml(YAML):是一个标记语言
以前配置文件都是*****.xml文件
yml以数据为中心,比json、xml更适合做配置文件
yml语法
server:
port:8081
properties语法
server.port=8070