springboot面试大全

https://blog.csdn.net/Kevin_Gu6/article/details/88547424

1 Spring Boot 有哪些优点?
起步依赖 自动配置 应用监控

2 springboot的核心配置文件,以及加载顺序?
bootstrap (.properties/ .yml) 用来加载系统相关的配置
application (.properties/ .yml) 用来加载应用相关的配置

bootstrap的加载优先级高于 application

3 开启springboot的两种方式?
1)继承spring-boot-starter-parent项目

<parent>  
<groupId>org.springframework.boot</groupId>   
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>

2)导入spring-boot-dependencies项目依赖

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.6.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    <dependencies>
</dependencyManagement>

parent方式只能单继承, 使用dependencyManagement导入的方式可以实现多继承。

4 springboot需要独立的容器运行吗?
不需要,内置了Tomcat等容器。

5 运行springboot有哪几种方式
1)使用java -jar命令直接运行jar文件
2)打成war包放到容器中运行
3)idea中直接执行main方法运行

6 springboot启动的时候如何运行一些特定的代码?
可以实现ApplicationRunner CommandLineRunner, 这两个接口都提供了run方法

ApplicationRunner: 获取应用启动时的参数
CommandLineRunner:启动获取命令行参数

7 springboot有几种读取配置的方式?
1)@Value
直接使用在属性上,如下:

@Value("${info.address}")
private String address;

2)@ConfigurationProperties
适用于一类属性设置到某个实体类中,如下:

@Component
@ConfigurationProperties(prefix="info")
@Data
public class InfoConfig{
private String address;
private String company;
}

8 springboot实现热部署的方式?
使用devtools依赖,并在idea开发工具中开启 auto compile

9 springboot如何定义多套不同环境配置
基于properties文件类型

你可以另外建立3个环境下的配置文件:

applcation.properties

application-dev.properties
application-test.properties
application-prod.properties

然后在applcation.properties文件中指定当前的环境spring.profiles.active=test,这时候读取的就是application-test.properties文件。

10 javabean什么时候创建的?
在执行refreshContext方法时创建的, @SpringBootApplication只是扫描到这些bean,还没有完成实例化,在refreshContext中
通过反射机制实例化,设置属性。

11 springboot使用的是单例吗?多例怎么设置?
是的, 使用单例在初始的时候统一创建,不用每次都创建,自然是更快。
多例的设置,通过注解@Scope(“prototype”)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值