zoukankan      html  css  js  c++  java
  • springboot笔记01

     每个SpringBoot程序都有一个主入口,也就是main方法,main里面调用SpringApplication.run()启动整个spring-boot程序,该方法所在类需要使用@SpringBootApplication注解,以及@ImportResource注解(if need),@SpringBootApplication包括三个注解,功能如下:@EnableAutoConfiguration:SpringBoot根据应用所声明的依赖来对Spring框架进行自动配置

    @SpringBootConfiguration(内部为@Configuration):被标注的类等于在spring的XML配置文件中(applicationContext.xml),装配所有bean事务,提供了一个spring的上下文环境

    @ComponentScan:组件扫描,可自动发现和装配Bean,默认扫描SpringApplication的run方法里的Booter.class所在的包路径下文件,所以最好将该启动类放到根包路径下

    2.实际上@Configuration可以理解为xml中的beans标签,而@Bean可以理解为bean标签

    例如:


    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
    default-lazy-init="true">
    <!--bean定义-->
    </beans>
    /////这两种方式的配置是一种效果
    @Configuration
    public class MockConfiguration{
    //bean定义 

    }

    3 @ComponentScan

    组件扫描,可自动发现和装配Bean,默认扫描SpringApplication的run方法里的Booter.class所在的包路径下文件,所以最好将该启动类放到根包路径下

    这个注解在Spring中很重要,他赌赢了XML配置的元素。@ComponentScan的功能其实就是自动扫描并加载到符合条件的组件中(比如@Component和@Repository)或者Bean的定义,最终将这些bean加载IOC容器中。我们可以通过BasePackge等属性来细粒度定制@ComponentScan自动扫描的范围,如果不指定,则任务spring框架会从声明出开始扫描。

     

  • 相关阅读:
    iOS:后台定位并实时向服务器发送位置
    iOS:创建Siri 功能
    Cocoa编程开发者手册
    iOS应用开发最佳实践
    Linux Shell编程与编辑器使用详解
    从虚拟化到云计算
    软件集成策略——如何有效率地提升质量
    水色物语:清新水彩手绘插画技法
    易用为王:改进产品设计的10个策略
    iOS Web应用开发:运用HTML5、CSS3与JavaScript
  • 原文地址:https://www.cnblogs.com/handsome1013/p/10981640.html
Copyright © 2011-2022 走看看