zoukankan      html  css  js  c++  java
  • 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);
          }
      
      }
      

        

  • 相关阅读:
    二分查找算法
    Python基础二(基础数据类型)
    Python基础一
    mysql 数据库
    Scrapy (网络爬虫框架)入门
    列表推导式的使用
    Scrapy(爬虫框架)中,Spider类中parse()方法的工作机制
    vim 基础命令大全
    windows cmd 命令大全
    类与类的关系一
  • 原文地址:https://www.cnblogs.com/oskyhg/p/6637152.html
Copyright © 2011-2022 走看看