fish 11 months ago
parent
commit
37c1e53bb5

+ 1 - 2
README.md

@@ -4,7 +4,6 @@ springboot 学习笔记
 
 ## Reference
 
-- [ityouknow/spring-boot-examples](https://github.com/ityouknow/spring-boot-examples)
 - [springboot-note 文档](https://wiki.yoqi.me/springboot-note)
 
 
@@ -36,7 +35,7 @@ https://github.com/niumoo/springboot
 https://github.com/dunwu/spring-boot-tutorial
 https://github.com/dyc87112/SpringBoot-Learning
 
-
+https://github.com/ityouknow/awesome-spring-boot
 快速创建spring应用 https://github.com/spring-projects/spring-boot
 
 # spring-boot

+ 33 - 0
deploy/app/src/main/java/com/neo/aa/api/v1/HelloController.java

@@ -0,0 +1,33 @@
+package me.yoqi.api.v1;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ */
+
+//@ResponseBody
+//@Controller
+@RestController
+@RequestMapping("/hello")
+public class HelloController {
+
+    @Value("${person.name}")
+    private String name;
+
+//    @PutMapping
+//    @DeleteMapping
+//    @PostMapping
+//    @GetMapping
+    @RequestMapping
+    public String sayHello(){
+        return  "hello world"+name;
+    }
+
+    @GetMapping({"/sayHello2",""})
+    public String sayHello2(){
+        return  "哈哈";
+    }
+}

+ 31 - 0
deploy/app/src/main/java/com/neo/aa/api/v1/UserController.java

@@ -0,0 +1,31 @@
+package me.yoqi.api.v1;
+
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Created by liuyuqi on 9/22/2019.
+ */
+
+@RestController
+@RequestMapping("user")
+public class UserController {
+
+//    http://localhost:8080/user/get
+    @GetMapping("/get")
+    public String getUser(){
+        return "哈哈";
+    }
+
+    @GetMapping("set")
+    public void setUser(){
+        return;
+    }
+
+    @DeleteMapping("del")
+    public void delUser(){
+        return;
+    }
+}

+ 20 - 0
deploy/app/src/main/java/com/neo/aa/config/MyAppConfig.java

@@ -0,0 +1,20 @@
+package me.yoqi.config;
+
+import me.yoqi.service.HelloService;
+        import org.springframework.boot.context.properties.ConfigurationProperties;
+        import org.springframework.context.annotation.Configuration;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ *
+ * @Configuration 表示当前类是一个配置类
+ */
+@Configuration
+public class MyAppConfig {
+
+    public HelloService helloService() {
+        System.out.println("配置类Beans给当前类添加组件了");
+        return new HelloService();
+    }
+
+}

+ 14 - 0
deploy/app/src/main/java/com/neo/aa/config/WebConfig.java

@@ -0,0 +1,14 @@
+package me.yoqi.config;
+
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+/**
+ * Created by liuyuqi on 9/23/2019.
+ */
+public class WebConfig extends WebMvcConfigurerAdapter {
+    @Override
+    public void addViewControllers(ViewControllerRegistry registry) {
+        registry.addViewController("/haha").setViewName("success");
+    }
+}

+ 24 - 0
deploy/app/src/main/java/com/neo/aa/controller/hello/HelloController.java

@@ -0,0 +1,24 @@
+package me.yoqi.controller.hello;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ */
+@RestController
+public class HelloController {
+
+    @Value("${person.name}")
+    private String name;
+
+    @Value("${afs.clientid}")
+    private String clientID;
+
+    @RequestMapping
+    public String sayHello(){
+        return  "hello world"+name+clientID;
+    }
+}

+ 33 - 0
deploy/app/src/main/java/com/neo/aa/model/Dog.java

@@ -0,0 +1,33 @@
+package me.yoqi.model;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ */
+public class Dog {
+    private String name;
+    private Integer age;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    @Override
+    public String toString() {
+        return "Dog{" +
+                "name='" + name + '\'' +
+                ", age=" + age +
+                '}';
+    }
+}

+ 105 - 0
deploy/app/src/main/java/com/neo/aa/model/Person.java

@@ -0,0 +1,105 @@
+package me.yoqi.model;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ *  @ConfigurationProperties 本类中所有属性都是配置文件中的属性,进行绑定。
+ */
+@Component
+@ConfigurationProperties(prefix = "person")
+public class Person {
+    private String name;
+    private int age;
+    private  Boolean sex;
+    private  boolean isBoss;
+    private Date birth;
+
+    private Map<String,Object> maps;
+    private List<Object> lists;
+
+    private Dog dog;
+
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String toString() {
+        return "Pserson{" +
+                "name='" + name + '\'' +
+                ", age=" + age +
+                ", sex=" + sex +
+                ", isBoss=" + isBoss +
+                ", birth=" + birth +
+                ", maps=" + maps +
+                ", lists=" + lists +
+                ", dog=" + dog +
+                '}';
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public Boolean getSex() {
+        return sex;
+    }
+
+    public void setSex(Boolean sex) {
+        this.sex = sex;
+    }
+
+    public boolean isBoss() {
+        return isBoss;
+    }
+
+    public void setBoss(boolean boss) {
+        isBoss = boss;
+    }
+
+    public Date getBirth() {
+        return birth;
+    }
+
+    public void setBirth(Date birth) {
+        this.birth = birth;
+    }
+
+    public Map<String, Object> getMaps() {
+        return maps;
+    }
+
+    public void setMaps(Map<String, Object> maps) {
+        this.maps = maps;
+    }
+
+    public List<Object> getLists() {
+        return lists;
+    }
+
+    public void setLists(List<Object> lists) {
+        this.lists = lists;
+    }
+
+    public Dog getDog() {
+        return dog;
+    }
+
+    public void setDog(Dog dog) {
+        this.dog = dog;
+    }
+}

+ 108 - 0
deploy/app/src/main/java/com/neo/aa/model/Person2.java

@@ -0,0 +1,108 @@
+package me.yoqi.model;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ *  @ConfigurationProperties 本类中所有属性都是配置文件中的属性,进行绑定。
+ */
+@Component
+public class Person2 {
+    @Value("${person.name}")
+    private String name;
+    @Value("${person.age}")
+    private int age;
+
+    private  Boolean sex;
+    @Value("true")
+    private  boolean isBoss;
+    private Date birth;
+
+    private Map<String,Object> maps;
+    private List<Object> lists;
+
+    private Dog dog;
+
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String toString() {
+        return "Pserson{" +
+                "name='" + name + '\'' +
+                ", age=" + age +
+                ", sex=" + sex +
+                ", isBoss=" + isBoss +
+                ", birth=" + birth +
+                ", maps=" + maps +
+                ", lists=" + lists +
+                ", dog=" + dog +
+                '}';
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public Boolean getSex() {
+        return sex;
+    }
+
+    public void setSex(Boolean sex) {
+        this.sex = sex;
+    }
+
+    public boolean isBoss() {
+        return isBoss;
+    }
+
+    public void setBoss(boolean boss) {
+        isBoss = boss;
+    }
+
+    public Date getBirth() {
+        return birth;
+    }
+
+    public void setBirth(Date birth) {
+        this.birth = birth;
+    }
+
+    public Map<String, Object> getMaps() {
+        return maps;
+    }
+
+    public void setMaps(Map<String, Object> maps) {
+        this.maps = maps;
+    }
+
+    public List<Object> getLists() {
+        return lists;
+    }
+
+    public void setLists(List<Object> lists) {
+        this.lists = lists;
+    }
+
+    public Dog getDog() {
+        return dog;
+    }
+
+    public void setDog(Dog dog) {
+        this.dog = dog;
+    }
+}

+ 112 - 0
deploy/app/src/main/java/com/neo/aa/model/Person3.java

@@ -0,0 +1,112 @@
+package me.yoqi.model;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ *  @ConfigurationProperties 本类中所有属性都是配置文件中的属性,进行绑定。
+ */
+@Component
+@PropertySource(value = {"classpath:person.properties"})
+@ConfigurationProperties(prefix = "person")
+public class Person3 {
+    @Value("${person.name}")
+    private String name;
+    @Value("${person.age}")
+    private int age;
+
+    private  Boolean sex;
+    @Value("true")
+    private  boolean isBoss;
+    private Date birth;
+
+    private Map<String,Object> maps;
+    private List<Object> lists;
+
+    private Dog dog;
+
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String toString() {
+        return "Pserson{" +
+                "name='" + name + '\'' +
+                ", age=" + age +
+                ", sex=" + sex +
+                ", isBoss=" + isBoss +
+                ", birth=" + birth +
+                ", maps=" + maps +
+                ", lists=" + lists +
+                ", dog=" + dog +
+                '}';
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public Boolean getSex() {
+        return sex;
+    }
+
+    public void setSex(Boolean sex) {
+        this.sex = sex;
+    }
+
+    public boolean isBoss() {
+        return isBoss;
+    }
+
+    public void setBoss(boolean boss) {
+        isBoss = boss;
+    }
+
+    public Date getBirth() {
+        return birth;
+    }
+
+    public void setBirth(Date birth) {
+        this.birth = birth;
+    }
+
+    public Map<String, Object> getMaps() {
+        return maps;
+    }
+
+    public void setMaps(Map<String, Object> maps) {
+        this.maps = maps;
+    }
+
+    public List<Object> getLists() {
+        return lists;
+    }
+
+    public void setLists(List<Object> lists) {
+        this.lists = lists;
+    }
+
+    public Dog getDog() {
+        return dog;
+    }
+
+    public void setDog(Dog dog) {
+        this.dog = dog;
+    }
+}

+ 8 - 0
deploy/app/src/main/java/com/neo/aa/service/HelloService.java

@@ -0,0 +1,8 @@
+package me.yoqi.service;
+
+/**
+ * Created by liuyuqi on 8/31/2019.
+ */
+public class HelloService {
+
+}

+ 11 - 0
deploy/app/src/main/java/com/neo/aa/tools/Mail.java

@@ -0,0 +1,11 @@
+package me.yoqi.tools;
+
+/**
+ *  发邮件。
+ * Created by liuyuqi on 9/24/2019.
+ */
+public class Mail  {
+    public  boolean sentMail(){
+        return false;
+    }
+}

+ 20 - 0
deploy/app/src/main/java/com/neo/aa/tools/Scheduler.java

@@ -0,0 +1,20 @@
+package me.yoqi.tools;
+
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ *  定时任务: 定时下载,定时备份,定时更新,定时打印。
+ *  (1) @EnableScheduling
+ *  (2)@Scheduled(cron = "40 * * * * *")
+ * Created by liuyuqi on 9/24/2019.
+ */
+@Component
+public class Scheduler {
+
+    @Scheduled(cron = "40 * * * * *")
+    public void cron() throws Exception{
+        System.out.println("执行啦");
+        Thread.sleep(500);
+    }
+}

+ 9 - 0
deploy/app/src/main/java/com/neo/aa/tools/Sync.java

@@ -0,0 +1,9 @@
+package me.yoqi.tools;
+
+/**
+ *  spring 异步执行
+ * Created by liuyuqi on 9/24/2019.
+ */
+public class Sync {
+
+}

+ 18 - 0
deploy/app/src/main/java/com/neo/aa/utils/SMSUtils.java

@@ -0,0 +1,18 @@
+package me.yoqi.utils;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by liuyuqi on 9/26/2019.
+ */
+@Component
+public class SMSUtils {
+
+    @Value("${afs.clientid}")
+    public String clientid;
+
+    public void mPrint() {
+        System.out.println("clientid:::" + clientid);
+    }
+}

+ 420 - 0
docs/README.md

@@ -17,7 +17,427 @@ src/main/resources/application-test.properties
 src/main/resources/application.properties
 
 
+技术栈
+
+* springboot3.2 
+* mysql5.7
+* Redis
+* MongoDB
+* maven 3.5.0
+* jdk 11
+* tomcat
+
 ## Reference
 
 
 
+## springboot 版本对比
+
+| Spring Boot 2.x | Spring Boot 3.x  |                    |
+| :-------------- | :--------------- | ------------------ |
+| Spring版本      | Spring 5.x       | Spring 6.x         |
+| JDK版本         | >= 1.8           | >= 17              |
+| Tomcat版本      | 9.x              | 10.x               |
+| Annotation包    | javax.annotation | jakarta.annotation |
+| Servlet包       | javax.servlet    | jakarta.servlet    |
+| JMS包           | javax.jms        | jakarta.jms        |
+| JavaMail包      | javax.mail       | jakarta.mail       |
+
+
+
+
+# 静态资源
+
+css 样式;
+js 脚本;
+favicon.ico 图标等;
+
+Spring Boot 访问静态资源,默认有两个默认目录:
+
+
+
+-   `classpath/static` 目录:`src/main/resource`
+-   `ServletContext` 根目录下: `src/main/webapp`
+
+这里打包app.jar包后,WEB-INF 下面的 classes 目录为 classpath
+
+
+配置文件可以更改目录路径:
+
+在 properties 文件里面设置 spring.resources.static-locations 就ok了。
+
+
+```
+vim application.properties
+
+spring.resources.static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
+
+
+spring.mvc.static-path-pattern=/static/**
+
+```
+
+## 前后端分离
+
+
+## 配置日期格式化
+
+要让 Spring Boot 能够按照指定的格式进行日期类型转换,需要做以下步骤:
+
+-   定义一个 `MvcConfig` 类,让其实现 `WebMvcConfigurer` 接口;
+-   重写 `addFormatters` 方法;
+-   添加一个 `DateFormatter`;
+
+```java
+package site.exception.springbootdateformat.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.format.FormatterRegistry;
+import org.springframework.format.datetime.DateFormatter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class MvcConfig implements WebMvcConfigurer {
+
+    /**
+     * 配置日期格式化
+     * @param registry
+     */
+    @Override
+    public void addFormatters(FormatterRegistry registry) {
+        registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
+    }
+}
+```
+
+
+## 配置跨域
+
+实现 `addCorsMappings` 接口来添加规则来允许跨域访问:
+
+```java
+package site.exception.config;
+
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+public class CORSConfig extends WebMvcConfigurerAdapter {
+
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        // 允许所有跨域访问
+        registry.addMapping("/**");
+    }
+
+}
+```
+
+`/**` 允许所有域名都能够跨域访问,下面看看更为精细的控制:
+
+```JAVA
+package site.exception.config;
+
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+/**
+ * @author www.exception.site (exception 教程网)
+ * @date 2019/2/13
+ * @time 下午8:36
+ * @discription
+ **/
+public class CORSConfig extends WebMvcConfigurerAdapter {
+
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        registry.addMapping("/api/**")
+                .allowedOrigins("http://www.exception.site")
+                .allowedMethods("POST", "GET");
+    }
+
+}
+```
+
+通过上面的配置,只允许来自 [www.exception.site](https://www.exception.site/) 的跨域访问,并且限定只能对 `/api` 下的所有接口进行跨域访问,同时只能访问 `POST` 和 `GET` 方法。
+
+## Jackson 配置
+
+Jackson 是 Spring Boot 内置的 Json 解析框架,用来完成出入参的序列化和反序列化。通常,我们会在 Controller 类中方法上,加上 @RequestBody 或者 @ResponseBody 注解,Spring Boot 会自动对出入参做 Json 解析与转换工作。
+
+## 配置 Jetty 
+
+默认自带的 tomcat,可以改为jetty 轻量,添加依赖
+
+```xml
+<dependency>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-web</artifactId>
+    <!-- 移除掉默认支持的 Tomcat -->
+    <exclusions>
+        <exclusion>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-tomcat</artifactId>
+        </exclusion>
+    </exclusions>
+</dependency>
+
+<!-- 添加 jetty 依赖 -->
+<dependency>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-jetty</artifactId>
+</dependency>
+```
+
+
+
+## hello world
+
+pom.xml 配置
+
+
+```
+	<parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.1.4.RELEASE</version>
+		<relativePath/> <!-- lookup parent from repository -->
+	</parent>
+
+
+	<properties>
+		<java.version>1.8</java.version>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
+		
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+        </dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
+
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# spring boot 介绍
+
+## 微服务
+
+将一个大系统分割为多个独立的应用,拥有自己的进程。易部署,易扩展。
+
+## Spring boot
+
+## 它是如何工作的?
+
+Spring Boot 使用 **@EnableAutoConfiguration** 注解根据您添加到项目的依赖项自动配置您的应用程序。 例如,如果 MySQL 数据库在你的类路径上,但你没有配置任何数据库连接,那么 Spring Boot 会自动配置一个内存数据库。
+
+Spring Boot 应用程序的入口点是包含 **@SpringBootApplication** 注解的类和 main 方法。
+
+Spring Boot 通过使用 **@ComponentScan** 注解自动扫描项目中包含的所有组件。
+
+------
+
+## Spring Boot 启动器
+
+处理依赖管理对于大型项目来说是一项艰巨的任务。 Spring Boot 通过提供一组依赖项方便开发人员解决了这个问题。
+
+例如,如果您想使用 Spring 和 JPA 进行数据库访问,则在项目中包含 **spring-boot-starter-data-jpa** 依赖项就足够了。
+
+请注意,所有 Spring Boot 启动器都遵循相同的命名模式 **spring-boot-starter-** *,其中 * 表示它是应用程序的一种类型。
+
+### 示例
+
+请查看下面解释的以下 Spring Boot 启动器以更好地理解 −
+
+**Spring Boot Starter Actuator 依赖项** 用于监视和管理您的应用程序。 其代码如下所示 −
+
+```
+<dependency>
+   <groupId>org.springframework.boot</groupId>
+   <artifactId>spring-boot-starter-actuator</artifactId>
+</dependency>
+```
+
+**Spring Boot Starter Security 依赖项** 用于 Spring Security。 其代码如下所示 −
+
+```
+<dependency>
+   <groupId>org.springframework.boot</groupId>
+   <artifactId>spring-boot-starter-security</artifactId>
+</dependency>
+```
+
+**Spring Boot Starter web 依赖** 用于编写一个 Rest Endpoints。 其代码如下所示 −
+
+```
+<dependency>
+   <groupId>org.springframework.boot</groupId>
+   <artifactId>spring-boot-starter-web</artifactId>
+</dependency>
+```
+
+**Spring Boot Starter Thyme Leaf 依赖项** 用于创建 Web 应用程序。 其代码如下所示 −
+
+```
+<dependency>
+   <groupId>org.springframework.boot</groupId>
+   <artifactId>spring-boot-starter-thymeleaf</artifactId>
+</dependency>
+```
+
+**Spring Boot Starter Test 依赖项**用于编写测试用例。 其代码如下所示 −
+
+```
+<dependency>
+   <groupId>org.springframework.boot</groupId>
+   <artifactId>spring-boot-starter-test</artifactId>
+</dependency>
+```
+
+------
+
+## 自动配置
+
+Spring Boot Auto Configuration 根据您在项目中添加的 JAR 依赖项自动配置您的 Spring 应用程序。 例如,如果 MySQL 数据库在你的类路径上,但你没有配置任何数据库连接,那么 Spring Boot 会自动配置一个内存数据库。
+
+为此,您需要在 main 主类文件中添加 **@EnableAutoConfiguration** 注解或 **@SpringBootApplication** 注解。 然后,您的 Spring Boot 应用程序将被自动配置。
+
+观察以下代码以更好地理解 −
+
+```
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+
+@EnableAutoConfiguration
+public class DemoApplication {
+   public static void main(String[] args) {
+      SpringApplication.run(DemoApplication.class, args);
+   }
+}
+ 
+```
+
+------
+
+## Spring Boot 应用程序
+
+Spring Boot Application 的入口点是包含 **@SpringBootApplication** 注解的类。 这个类应该有运行 Spring Boot 应用程序的 main 方法。 **@SpringBootApplication** 注解包括自动配置、组件扫描和 Spring Boot 配置。
+
+如果在类中添加了**@SpringBootApplication**注解,则不需要添加**@EnableAutoConfiguration、@ComponentScan**和**@SpringBootConfiguration**注解。 **@SpringBootApplication** 注解包括所有其他注解。
+
+观察以下代码以更好地理解 −
+
+```
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class DemoApplication {
+   public static void main(String[] args) {
+      SpringApplication.run(DemoApplication.class, args);
+   }
+}
+ 
+```
+
+------
+
+## 组件扫描
+
+Spring Boot 应用程序在应用程序初始化时扫描所有 bean 和包声明。 您需要为您的类文件添加 **@ComponentScan** 注解以扫描您在项目中添加的组件。
+
+观察以下代码以更好地理解 −
+
+```
+import org.springframework.boot.SpringApplication;
+import org.springframework.context.annotation.ComponentScan;
+
+@ComponentScan
+public class DemoApplication {
+   public static void main(String[] args) {
+      SpringApplication.run(DemoApplication.class, args);
+   }
+}
+ 
+```
+