• Spring Boot(一)


    1、注解 

    1. @EnableAutoConfiguration                                                                 

      官方文档:The @EnableAutoConfiguration annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example, if you are writing a JPA application, the package of the@EnableAutoConfiguration annotated class will be used to search for @Entity items.

      @EnableAutoConfiguration通常用在主类上,它隐含地定义了某些项目的基本“搜索包”。如果您正在编写JPA应用程序,则@EnableAutoConfiguration注释类的包将用于搜索@Entity项。
      官方文档:You should only ever add one @EnableAutoConfiguration annotation. We generally recommend that you add it to your primary @Configuration class
      您应该只添加一个@EnableAutoConfiguration注释。我们通常建议您将其添加到主要的@Configuration类中。

    2. @Configuration 
      如果需要在启动 SpringApplication.run()时,需要加载xml文件,官方建议在main方法的类上加上该注解。也可以在多个类上使用该注解。 @Import注解可以导入配置类,另外使用 @ComponentScan 注解可以自动装载所有spring组件,包括@Configuration 注解的类。
    3. @ImportResource
      加载xml文件
    4. @ComponentScan
      自动扫描装载spring组件,比如(@Component@Service@Repository@Controller etc.)
                           
    5. @SpringBootApplication 
      使用@SpringBootApplication注释相当于使用@Configuration,@EnableAutoConfiguration和@ComponentScan及其默认属性:
      package com.example.myproject;
      
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      
      @SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
      public class Application {
      
          public static void main(String[] args) {
              SpringApplication.run(Application.class, args);
          }
      
      }
      

        

  • 相关阅读:
    CM金丝雀Canary报错
    ucloud自动创建instance
    拷贝文件
    10.使用du将文件按大小进行排序
    9.ssh登录慢
    8.perf top系统性能分析工具
    7.Linux查找目录下的所有文件中是否含有某个字符串
    6.Linux查看哪个进程占用磁盘IO
    5.Linux常用排查命令
    4.Linux系统命令及其使用详解
  • 原文地址:https://www.cnblogs.com/oskyhg/p/6637152.html
Copyright © 2020-2023  润新知