springboot tips

##1. SpringBoot是spring中的一个成员,简化spring,springMVC的使用,核心还是IOC容器

特点:(1) 创建Spring应用

(2)内嵌tomcat ,jetty ,undertow服务器

(3)提供starter起步依赖,简化应用的配置。比如使用MyBatis框架,在spring项目中,需要配置MyBatis的对象sqlSessionFactory,Dao的代理对象;而在Spring Boot项目中,只需在pom.xml中加入一个mybatis-spring-boot-starter依赖即可。

(4)尽可能去配置spring和第三方库,叫做自动配置(就是把spring中的,第三方库中的对象都创建好,放到容器中,开发人员可以直接使用)。

(5)提供了健康检查,统计,外部化配置功能。

(6)不用生成代码,不用使用xml,做配置。

##2.创建项目

(1) 使用Spring提供的初始化器,就是使用向导创建项目(Spring Initializr),使用国外地址:https://start.spring.io

(2) 使用国内地址:使用的地址:https://start.springboot.io (一般用这个地址)

(3)先创建maven项目,再将<parent></parent>父项目添加进去,再添加相关依赖

##3.SpringBoot核心注解

@SpringBootApplication : 复合注解,放在主启动类上面。整个项目从这里启动。

@SpringBootApplication
public class SpringbootMvcApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootMvcApplication.class, args);
    }
}

该注解主要由@SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan组成。

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {}

(1) @SpringBootConfiguration :

@Configuration
@Indexed
public @interface SpringBootConfiguration {
    @AliasFor(
        annotation = Configuration.class
    )
    boolean proxyBeanMethods() default true;
}
说明: 使用@SpringBootConfiguration注解标注的类,可以作为配置文件使用,可以使用@Bean声明该类对象,注入到容器。 

(2) @EnableAutoConfiguration:

启用自动配置,把java对象配置好,注入到Spring容器中。例如可以把mybatis的对象创建好,放入到容器中。

(3) @ComponentScan:

扫描器,扫描包,然后可以找到包下的类里面的注解,根据注解的功能创建对象,给属性赋值等等。

@ComponentScan注解默认扫描的包:@ComponentScan所在的类所在的包和子包。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值