Spring Boot 面試題總結

1.什麼是spring bootjava

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

2.springboot與spring的區別。web

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

         2)spring boot優於spring,配置簡單,並且能夠集成spring框架的項目。sql

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

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

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

4.spring boot中的application.properties配置文件幹什麼用的。mybatis

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

例如:能夠重寫試圖解析器的資源地址

         能夠重寫頁面默認前綴目錄: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)建立消息生產者,建立消息消費者

相關文章
相關標籤/搜索