Spring boot项目基础面试题

springboot项目基础面试题(一)

1.springboot与spring的区别.

引用自官方说法: java在集成spring等框架需要作出大量的配置,开发效率低,繁琐.所以官方提出 spring boot的核心思想:习惯优于配置.可以快速创建开发基于spring框架的项目.或者支持可以不用或很少的spring配置即可.

2.springboot的核心功能与使用优点.

核心功能:
  • 1.1: springboot项目为独立运行的spring项目,java -jar xx.jar即可运行.
  • 1.2: 内嵌servlet容器(可以选择内嵌: tomcat ,jetty等服务器.).
  • 1.3: 提供了starter的pom 配置 简化了 maven的配置.
  • 1.4: 自动配置spring容器中的bean.当不满足实际开发场景,可自定义bean的自动化配置.
  • 1.5: 准生产的应用监控(基于: ssh , http , telnet 对服务器运行的项目进行监控.).
  • 1.6: springboot无需做出xml配置,也不是通过代码生成来实现(通过条件注解.).
使用优点:
  • 1.快速搭建项目,
  • 2,与主流框架集成无需配置集成.
  • 3.内嵌服务容器.
  • 4.具有应用监控.
  • 5.开发部署方便,后期与云计算平台集成方便(docket).

3.springboot中的application.properties配置文件是什么,有哪些配置.

application.properties为boot项目中的一个系统自带的全局属性配置文件. 提供默认属性重写的作用. 可包含重写系统tomcat,spring,springmvc,mybatis等诸多默认配置属性: 列举部分如下:

#全局配置文件: 重写视图解析器的资源地址.
#页面默认前缀目录
spring.mvc.view.prefix=/WEB-INF/jsp/
#?响应页面默认后缀
spring.mvc.view.suffix=.jsp
#静态资源目录配置,
spring.mvc.static-path-pattern=/static/**

#tomcat服务器的配置:
server.port=8081
server.servlet.context-path=/sb2

#默认支持的日志记录:
#logging.config=classpath:logback.xml 加载单独的日志配置文件.
logging.file=d:/test/log.log
logging.level.org.springframework.web=DEBUG

#提供jdbc的基本配置:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/c01?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.type=org.apache.commons.dbcp.BasicDataSource
#提供mybatis的属性配置: 扫描.
mybatis.mapper-locations=classpath:mapper/*_mapper.xml

4.springboot中常用的starter的组件有哪些.

spring-boot-starter-parent //boot项目继承的父项目模块.
spring-boot-starter-web //boot项目集成web开发模块.
spring-boot-starter-tomcat //boot项目集成tomcat内嵌服务器.
spring-boot-starter-test //boot项目集成测试模块.
mybatis-spring-boot-starter //boot项目集成mybatis框架.
spring-boot-starter-jdbc //boot项目底层集成jdbc实现数据库操作支持.
其他诸多组件,可到maven中搜索,或第三方starter组件到github上查询 .....

5.springboot中的核心启动主函数(main函数)的作用.用到哪些注解.注解的作用.

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

该主函数: 主要启动springboot框架.用于加载容器和诸多默认组件.
用到核心注解:== @SpringBootApplication . 作用:用于标识声明一个springboot框架容器.==

6.springboot中的常用配置入口有哪些?

bootstrap.properties/bootstrap.yml //用于配置无需重写的系统常量,
//例如springcloud项目用到的config配置中心的连接属性等.加载优先级高于application.properties.
application.properties/application.yml //用于配置重写springboot项目的默认框架属性,
//例如:重写tomcat,springmvc,日志框架等默认属性.主要提供给spring框架加载使用.: properties后缀名与yml后缀名配置文件二选一即可. 两种不同格式的配置文件而已.

7.springboot项目需要兼容老项目(spring框架),该如何实现.

集成老项目spring框架的容器配置文件即可:
spring-boot一般提倡零配置.但是如果需要配置,也可增加:

@ImportResource({
   "classpath:spring1.xml" , "classpath:spring2.xml"})

注意:resources/spring1.xml位置.

8.需要加载外部配置文件中的自定义属性,该如何实现.

需求一批量加载多个属性.
步骤一: 首先需要自定义外部配置文件和其中的自定义属性:
user.properties . 存放在resources目录下:
内部:

#自定义配置其他属性:
user.username=zhangsan
user.age=20

步骤二: 加载属性到程序中:
springboot 1.5版本以及之前采用:br/>@ConfigurationProperties(prefix=“user”,locations=

{
   "classpath:user.propeties"})
public class User {
   
private String username;
private Integer age;
get/set封装省略....
}

springboot 1.5版本以后采用如下:

@PropertySource(value ="classpath:user.properties")
@ConfigurationProperties(prefix = "user")br
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值