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);
          }
      
      }
      

        

  • 相关阅读:
    initctl 创建自己的JOB
    TortoiseXX 与TotalCommander (TC)的图标问题
    eclipse 与 tomcat 的那些路径
    把函数视为对象
    序列增量赋值的一个谜题: +=
    __new__ 和 __init__ 的区别
    Python 中 is 与 == 区别
    Flask 2.0.1 changes
    flask run 与 DispatcherMiddleware 不兼容处理
    waitress 部署 flask服务
  • 原文地址:https://www.cnblogs.com/oskyhg/p/6637152.html
Copyright © 2011-2022 走看看