SpringBoot的入门搭建(二)

SpingBoot的核心


springboot的入口类

- SpringBoot的项目一般都会有*Application这样的入口类。而在这个入口类中还会有main方法,这也是一个标准的应用程序的入口

springboot中的@SpringBootAppllication注解的使用

- @SpringBootApplicationSpringBoot的核心注解,@SpringBootAppllication也可以进行拆分
- @SpringBootApplication是一个组合注解:
    - 主要包括
        - @Target({ElementType.TYPE})
        - @Retention(RetentionPolicy.RUNTIME)
        - @Documented
        - @Inherited
        - @SpringBootConfiguration
        - @EnableAutoConfiguration
        - @ComponentScan(
            excludeFilters = {@Filter(
            type = FilterType.CUSTOM,
            classes = {TypeExcludeFilter.class}
        ), @Filter(
            type = FilterType.CUSTOM,
            classes = {AutoConfigurationExcludeFilter.class}
        )}
        )
    - 也就是说已经包括@Configurtion注解,我们直接用@SpringBootApplication接可以了,无需用@Configurtion注解了
    - [在Spring Boot项目中推荐使用@ SpringBootConfiguration替代@Configuration]
    - @EnableAutoConfiguration:启用自动配置,该注解会使Spring Boot根据项目中依赖的jar包自动配置项目的配置项:
        - a)    如:我们添加了spring-boot-starter-web的依赖,项目中也就会引入SpringMVC的依赖,Spring Boot就会自动配置tomcat和SpringMVC
    - @ComponentScan:默认扫描@SpringBootApplication所在类的同级目录以及它的子目录。

这里写图片描述

springboot中的@SpringBootApplication(exclude = “”)注解的使用

关闭自动配置
- 通过上述,我们得知,Spring Boot会根据项目中的jar包依赖,自动做出配置,Spring Boot支持的自动配置如下(非常多):
- 现在我们不加在那么多的配置,进行自定义配置:
    - 比如:我们不想自动配置Redis,想手动配置
        - @Controller
        - @SpringBootApplication(exclude = RedisAutoConfiguration.class)
    - 其他的配置就类似

这里写图片描述

自定义启动的Banner

描述:
我们在启动SpringBoot的时候,往往看到SpringBoot的启动Banner这样我们怎样可以自定义呢??

1.http://patorjk.com/software/taag/#p=display&h=3&v=3&f=4Max&t=itcast%20Spring%20Boot
2. 拷贝生成的字符到一个文本文件中,并且将该文件命名为banner.txt
3. 将banner.txt拷贝到项目的resources目录中:
4. 这里写图片描述
5. 重新启动程序,查看效果
6. 如果不想看到任何的banner,也是可以将其关闭的
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值