美文网首页
面试:springboot

面试:springboot

作者: 奇点一氪 | 来源:发表于2018-07-30 14:12 被阅读36次

    什么是springboot

    用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(properties或yml文件)
    创建独立的spring引用程序 main方法运行
    嵌入的Tomcat 无需部署war文件
    简化maven配置
    自动配置spring添加对应功能starter自动化配置

    springboot常用的starter有哪些

    spring-boot-starter-web 嵌入tomcat和web开发需要servlet与jsp支持
    spring-boot-starter-data-jpa 数据库支持
    spring-boot-starter-data-redis redis数据库支持
    spring-boot-starter-data-solr solr支持
    mybatis-spring-boot-starter 第三方的mybatis集成starter

    springboot自动配置的原理

    在spring程序main方法中 添加@SpringBootApplication或者@EnableAutoConfiguration会自动去maven中读取每个starter中的spring.factories文件 该文件里配置了所有需要被创建spring容器中的bean

    springboot读取配置文件的方式

    springboot默认读取配置文件为application.properties或者是application.yml

    springboot集成mybatis的过程

    添加mybatis的starter maven依赖
    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.2.0</version>
    </dependency>
    在mybatis的接口中 添加@Mapper注解
    在application.yml配置数据源信息

    如何使用 SpringBoot 自动重装我的应用程序?

    使用 Spring Boot 开发工具。
    把 Spring Boot 开发工具添加进入你的项目是简单的。
    把下面的依赖项添加至你的 Spring Boot Project pom.xml 中
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    </dependency>
    重启应用程序,然后就可以了

    我们能否在 spring-boot-starter-web 中用 jetty 代替 tomcat?

    在 spring-boot-starter-web 移除现有的依赖项,并把下面这些添加进去。
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
    <exclusion>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

    RequestMapping 和 GetMapping 的不同之处在哪里?

    • RequestMapping 具有类属性的,可以进行 GET,POST,PUT 或者其它的注释中具有的请求方法。
    • GetMapping 是 GET 请求方法中的一个特例。它只是 ResquestMapping 的一个延伸,目的是为了提高清晰度

    相关文章

      网友评论

          本文标题:面试:springboot

          本文链接:https://www.haomeiwen.com/subject/yhbtvftx.html