Spring Boot 面試題總結


1.什么是spring boot

答案:springboot是用來簡化spring應用的初始搭建和開發過程,使用特定的配置文件來配置,例如application.properties,簡化來maven配置,使項目從繁到簡。

2.springboot與spring的區別。

答案:1)Java在集成spring框架時需要配置大量的配置文件,開發效率低。

         2)spring boot優於spring,配置簡單,而且可以集成spring框架的項目。

3.sprinboot的核心功能和使用優點。

核心功能:內嵌servlet容器(tomcat,jetty) 提供了start的pom配置,簡化了maven的配置   自動配置spring的bean,如果不滿足開發需求,可自定義bean的自動化配置。

使用優點:快速搭建項目,與主流框架集成無需配置,部署簡單。

4.spring boot中的application.properties配置文件干什么用的。

application.properties文件是boot項目中自帶的全劇屬性配置文件,可以重寫默認屬性,如tomcat,spring,springmvc,mybatis

例如:可以重寫試圖解析器的資源地址

         可以重寫頁面默認前綴目錄:prefix,后綴:suffix

         靜態資源位置的重寫

         spring.mvc.static-path-pattern=/static/*

         tomcat的重寫

        server.port=8081
        server.servlet.context-path=/sb2

        mybatis映射文件的掃描

    mybatis.mapper-locations=classpath:mapper/*_mapper.xml

        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

5.springboot中常用的start組件有哪些。

spring-boot-starter-parent 繼承父類

mybatis-spring-boot-starter 集成mybatis框架

spring-boot-starter-test:測試模塊集成

spring-boot-starter-web:web項目

6.springboot核心啟動函數有哪些作用,用到的核心注解有什么作用。

main:主要作用啟動spring boot框架,加載容器和諸多默認組件。

核心注解:springbootApplication:用於標示聲明一個spring boot礦機。

7.springboot常用的配置入口有哪些。

bootstrup.properties:用於配置不需要重寫的屬性。

application.proterties:用於配置默認屬性,可以重寫。

8.springboot框架的項目需要兼容老項目(spring框架),該如何實現。

集成老項目spring框架所需要的配置文件即可,也可添加所需的資源,@ImportResource({"classpath:spring1.xml" , "classpath:spring2.xml"})

9.需要加載外部配置文件的屬性,該如何配置。

1)自定義所需的配置文件。

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

2)將配置文件引入到程序中:@PropertySource,@ConfigrationProperties

@PropertySource(value ="classpath:user.properties")
@ConfigurationProperties(prefix = "user")
br/>@Component
public class User {
private String username;
private Integer age;
get/set封裝省略....
}

3)在main啟動函數中加入注解激活配置:@EnableConfigrationProperties.

10.spring boot的開發環境和測試環境該如何實現切換。

創建一個application-test.properties:用於測試環境

創建一個application-pro.properties:用於正式環境

在application.properties:配置spring.profiles.active=pro即可

11.spring boot和springmvc如何實現集成

1.添加pom

2.在application.properties中添加配置:

頁面默認前綴目錄:spring.mvc.view.prefix=/WEB-INF/jsp/

頁面默認后綴:spring.mvc.view.suffix=.jsp

靜態資源配置目錄:spring.mvc.static-path-pattern=/static/**

3.編寫controller和jsp即可

12.springboot和mybatis如何實現集成。

1)添加pom:mybatis,connect

2)在application.properties配置mapper.xml的位置

3)新建Mapper.java ,這是接口,用於管理方法。

4)在resouce下新建mapper.xml,完成mapper.java中的抽象方法的具體實現。

5)spring容器掃描接口,@MapperScan():掃描的是mapper.java所在的包

13.spring boot常用的啟動部署方式有哪些。

1.main函數啟動。

2.使用mvn install package打包

14.如何集成spring boot和activeMQ

1)添加依賴

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> </dependency>

2)在application.properties中添加配置

復制代碼
spring.activemq.broker-url=tcp://192.168.74.135:61616
spring.activemq.user=admin
spring.activemq.password=admin
spring.activemq.pool.enabled=true
spring.activemq.pool.max-connections=50
spring.activemq.pool.expiry-timeout=10000
spring.activemq.pool.idle-timeout=30000
復制代碼

3)創建消息生產者,創建消息消費者


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM