zoukankan      html  css  js  c++  java
  • 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)创建消息生产者,创建消息消费者

  • 相关阅读:
    Yii2的相关学习记录,后台模板和gii(三)
    Yii2的相关学习记录,初始化Yii2(二)
    Yii2的相关学习记录,下载Yii2(一)
    虚拟机上网总结
    纯Java实现微信朋友圈分享图
    【集合框架】JDK1.8源码分析之ArrayList详解(一)
    Java中字符串相加和字符串常量相加区别
    onTouchEvent中,跟随手指滑动的view出现抖动
    Android CHM文件阅读器
    CHM格式
  • 原文地址:https://www.cnblogs.com/yang-yutao/p/11553132.html
Copyright © 2011-2022 走看看