• SpringBoot基础


    1. 创建Maven项目
    2. pom导入springboot

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.6.RELEASE</version>
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

    3. 创建主入口 @SpringBootApplication,main方法启动
    4. 创建Controller @RestController,访问方法 @RequestMapping("/kkkk/llll")

    ------------------------------------------------------
    注解
    Spring Boot:
      @AutoConfiguration 。
      @SpringBootApplication 主启动类。
      @EnableAutoConfiguration @Import的支持,收集和注册依赖包中相关的bean定义。将所有符合条件的@Configuration配置都加载到当前SpringBoot创建并使用的IOC容器。

    Spring:
      @ConfigurationProperties(prefix="XXX") 自动把配置文件对应类XXX的值装配到类XXX。
      @Value("${XXX.XXX}") 单个值装配。
      @Autowired 变量、方法及构造函数自动装配。
      @Configuration 被注解的类将成为一个bean配置类。
      @ComponentScan 自动扫描并加载符合条件的组件,比如@Component和@Repository等,最终将这些bean定义加载到spring容器中。
      @EnableConfigurationProperties(Xxxx.class) 启用配置属性功能,在yml中配置属性
      @ConditionalXxx 该组件加载入Spring容器的条件

    ------------------------------------------------------
    SpringBoot 2.0
    最低Spring5
    最低JDK1.8

    ------------------------------------------------------
    springboot通过默认配置了很多框架的使用方式帮我们大大简化了项目初始搭建以及开发过程
    工作原理:
    1. 读取spring.factories文件
    /spring-boot-autoconfigure-2.1.6.RELEASE.jar!/META-INF/spring.factories,读取EnableAutoConfiguration属性的值加载自动配置类。
    2. 加载XxProperties类
    根据自动配置类中指定的XxxProperties类设置自动装配的属性值,开发者也可以根据XxxProperties类中指定的属性在yml配置文件中修改自动配置(属性默认值)。
    3. 根据@ConditionalXxx注解决定加载哪些组件
    SpringBoot通过@ConditionalXxx注解指定特定组件加入IOC容器时所具备的特定条件,这个组件会在满足条件时加入IOC容器。

    ------------------------------------------------------
    打jar包需要添加build依赖(maven-plugin)

    (个人学习笔记,有问题欢迎指出)

            积极竞争
        不惧失败
    学习提升
  • 相关阅读:
    深入浅出百度地图API开发系列(3):模块化设计
    深入浅出百度地图API开发系列(2):创建地图
    深入浅出百度地图API开发系列(1):前言
    使用分页助手pageHelper,方便快捷
    mybatis注解模糊查询的两种方式
    idea svn 提交拉取代码抛出 Error:'C:Program' 不是内部或外部命令,也不是可运行的程序 或批处理文件
    Could not open ServletContext resource [/WEB-INF/applicationContext.xml]”解决方案
    com.sun.jersey.api.client.UniformInterfaceException
    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
    继承关系,子类初始化,类中成员的加载顺序
  • 原文地址:https://www.cnblogs.com/acmez/p/13609282.html
Copyright © 2020-2023  润新知