山东大学 暑期实训 云主机服务比价与预测系统(十一)Spring boot原理 自动配置1
Condition
条件判断功能,能够帮助程序员完成选择性创建bean操作
常用地注解判断不同情况
@ConditionalOnProperty
判断配置文件中是否有对应属性和值才初始化Bean
@ConditionalOnClass
判断环境中是否有对应字节码文件才初始化Bean
@ConditionalOnMissingBean
判断环境中没有对应Bean才初始化Bean
切换内置web服务器
Spring boot默认使用tomcat服务器
除此以外还有
Jetty ,Netty ,Undertow等三种web服务器
Spring boot可以在四种服务器之间切换使用
可以在pom.xml中通过修改以来来切换内置服务器
//删除tomcat依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>rg.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
//导入jetty依赖
<dependency>
<artifactId>spring-boot-starter-jetty</artifactId>
<groupId>rg.springframework.boot</groupId>
<dependency>
@Enable*注释
Springboot中提供了很多Enable开头的注解,这些注解一般用于动态启用某些功能,导入配置类,实现Bean的动态加载