1.pom文件
父项目
1 <parent> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-parent</artifactId> 4 <version>2.0.4.RELEASE</version> 5 </parent> 6 7 spring-boot-starter-parent 的 父项目是这个 8 <parent> 9 <groupId>org.springframework.boot</groupId> 10 <artifactId>spring-boot-dependencies</artifactId> 11 <version>2.0.4.RELEASE</version> 12 <relativePath>../../spring-boot-dependencies</relativePath> 13 </parent> 14 15 父项目里面的定义了个软件的版本号,当我们引入相关包的时候,不需要再写包版本号,如果里面没有的,那就肯定要写版本号了。 16 称之为:SpringBoot的版本仲裁中心
启动器
1 <!-- 导入Spirng Boot web 所需的jar包 --> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-web</artifactId> 5 </dependency>
spring-boot-starter-web:帮我们导入了web模块正常运行所依赖的组件;
spring-boot-starter:spring-boot场景启动器;
SpringBoot开发主要都是围绕导入场景启动器;
2.主程序类,主入口类
1 /** 2 * 来标注一个主程序类,说明这是 Spring Boot 的应用 3 */ 4 @SpringBootApplication 5 public class HelloWorldMainApplication { 6 // psvm 快捷键 7 public static void main(String[] args) { 8 // Spring 应用启动起来 9 SpringApplication.run(HelloWorldMainApplication.class, args); 10 } 11 }
@SpringBootApplication:Spring Boot应用标注在某个类上说明这个类是SpringBoot的主配置类,SpringBoot就应该运行这个类的main方法来启动SpringBoot应用;
1 @Target({ElementType.TYPE}) 2 @Retention(RetentionPolicy.RUNTIME) 3 @Documented 4 @Inherited 5 @SpringBootConfiguration // 配置类,下面更详细讲解。 6 @EnableAutoConfiguration // 开启自动配置功能,下面更加详细讲解。 7 @ComponentScan(excludeFilters = { 8 @Filter(type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class}), 9 @Filter(type = FilterType.CUSTOM, classes = {AutoConfigurationExcludeFilter.class})} 10 ) 11 public @interface SpringBootApplication { // 上面多个注解表明是一个组合注解
@SpringBootConfiguration:SpringBoot的配置类,标注在某个类上,表示这是一个SpringBoot的配置类,其实就是用于区分下Spring,两个其实是一样的
@Configuration:配置类上来标注这个注解
配置类 --- 配置文件;配置类也是容器中的一个组件;@Component
@EnableAutoConfiguration:开启自动配置功能 以前我们需要配置的东西,SpringBoot帮我们自动配置;
@AutoConfigurationPackage:开启自动配置包
@Import({Registrar.class})
Spring底层注解@Import,给容器导入一个组件。
将主配置类(@SpringBootApplication标注的类)的所在下面子包的所有组件扫描到Spring容器。
@Import({AutoConfigurationImportSelector.class})
导入那些组件的选择器;将所有需要导入的组件以全类名方式返回,这些组件自动导入。
详细的,后面再学。
J2EE的整体解决方案和自动配置都在spring-boot-autoconfigure-2.0.4.RELEASE.jar
-
static:保存所有的静态资源; js css images;
-
templates:保存所有的模板页面;(Spring Boot默认jar包使用嵌入式的Tomcat,默认不支持JSP页面);可以使用模板引擎(freemarker、thymeleaf);
-
application.properties:Spring Boot应用的配置文件;可以修改一些默认设置;
源码
https://files.cnblogs.com/files/jtfr/spring-boot-01-helloworld.zip
来源:https://www.cnblogs.com/jtfr/p/10392244.html