• Hello world主程序类主入口


    一、
    /**
    *@SpringBootApplication来标注一个主程序类,说明这是一个Spring Booot应用
    */
    @SpringBootApplication
    public class HelloWorldApplication {

    public static void main(String[] args){
    //springboot应用启动
    SpringApplication.run(HelloWorldApplication.class,args);
    }
    }
    @SpringBootApplication:Spring  Boot应用标注在某个类上说明这个类是SpringBoot的主配置类,SpringBoot1就应该运行这个类的Main()方法来启动SpringBoot应用

    @SpringBootConfiguration:配置类(配置文件),标注在某个类上,表示一个SpringBoot的配置类
    Spring定义的注解@Configuration:配置类上来标注这个注解;

    @EnableAutoConfiguration:开启自动配置功能
    @AutoConfigurationPackage:自动配置包
    @Import(AutoConfigurationPackages.Registrar.class):
    Spring的底层注解@Import,给容器中导入一个组件;
    AutoConfigurationPackages.Registrar.class:将主配置类(@SpringBootApplication标注的类)的所在的包及以下所有子包里面的所有组件扫描到Spring容器中;
    @Import
    SpringFactoriesLoader.loadfactoryNames(EnableAutoConfiguration.class.classLoader);
    SpringBoot在启动的时候从类路径下的META/spring.factories中获取EnableAutoConfiguration指定的值,将这些值作为自动配置类导入到容器中,自动配置类生效。
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version>
    <relativePath/>
    </parent>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    spring-boot-starter:场景启动器,导入web模块正常运行所依赖的组件
    Spring Boot将所有的功能场景都抽取出来,做成一个个starters(启动器),只需要在项目引用这些starer相关场景的所有依赖都会导入进来,要用什么功能就导入什么场景的依赖器。

    二、使用Spring Initializer快速创建Spring Boot项目

    1、IDE都支持使用Spring的项目创建向导快速创建一个Spring Boot项目;向导创建项目必须联网;

    2、默认生成的SpringBoot项目:

    • 主程序自动生成只需编写业务逻辑
    • 配置文件resources的目录结构:static保存所有静态资源;temolates:保存所有模板页面(SpringBoot默认嵌入式的Tomcat,不支持jsp页面,可以使用模板引擎)
    • application.properties:Springboot应用的配置文件,可以修改一些默认配置

    3、步骤:

    File->NewProject->Spring Initializer->选中"project SDK"->next->填写工程名字->next->选择要使用的模块

    4、自动导入包

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.atguigu</groupId>
    <artifactId>spring-boot-01-helloworld-quick</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-01-helloworld-quick</name>
    <description>Demo project for Spring Boot</description>

    <properties>
    <java.version>1.8</java.version>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--Spring Boot进行单元测试模块-->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
    <exclusion>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>
    </build>
    </project>


  • 相关阅读:
    状态机
    折半查找函数
    宽字符与多字符相互转换
    安装交叉编译工具
    make menuconfig提示'make menuconfig' requires the ncurses libraries.
    IIC总线
    关于文字编码
    傅里叶变换
    韦东山视频_第27课_dma设备驱动程序
    linux内核宏之——-PERF_ALIGN
  • 原文地址:https://www.cnblogs.com/lz-huihui/p/11925246.html
Copyright © 2020-2023  润新知