SpingBoot的核心
springboot的入口类
- SpringBoot的项目一般都会有*Application这样的入口类。而在这个入口类中还会有main方法,这也是一个标准的应用程序的入口
springboot中的@SpringBootAppllication注解的使用
- @SpringBootApplication是SpringBoot的核心注解,@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,也是可以将其关闭的