2018-03-05
springboot-核心功能
springboot 评论:0 浏览:106

转载请注明出处:https://oldnoop.tech/c/130.html

自动配置

针对很多Spring应用程序常见的应用功能,Spring Boot能自动提供相关配置。
比如:
---------------------------------------
springboot如果在Classpath里发现JdbcTemplate,那么它还会为你配置一个 JdbcTemplate 的Bean
而不需要手动的进行如下    数据源和jdbctemplate 的配置
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
    return new JdbcTemplate(dataSource);
}

@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
    .setType(EmbeddedDatabaseType.H2)
    .addScripts('schema.sql', 'data.sql')
    .build();
}


起步依赖


告诉Spring Boot需要什么功能,它就能引入需要的库。
不需要去关心具体依赖的groupId,artifactId,以及是否有jar包冲突
比如:
---------------------------------------
用Spring MVC编写一个REST接口,并返回JSON格式的数据

只需添加Spring Boot的Web起步依赖(org.springframework.boot:spring-boot-starter-web)

而不需要手动引入很多的依赖jar包,比如如下jar包依赖

org.springframework:spring-core
org.springframework:spring-web
org.springframework:spring-webmvc
com.fasterxml.jackson.core:jackson-databind
org.hibernate:hibernate-validator
org.apache.tomcat.embed:tomcat-embed-core
org.apache.tomcat.embed:tomcat-embed-el
org.apache.tomcat.embed:tomcat-embed-logging-jul

命令行界面


这是Spring Boot的可选特性,
借此你只需写代码就能完成完整的应用程序,
无需传统项目构建


Actuator


可以在运行时 检查应用程序的内部情况
可以通过 web界面/命令行 2种方式 查看应用程序内部的信息
包括如下信息:
    Spring应用程序上下文里配置的Bean
    Spring Boot的自动配置做的决策
应用程序取到的环境变量、系统属性、配置属性和命令行参数
应用程序里线程的当前状态
应用程序最近处理过的HTTP请求的追踪情况
各种和内存用量、垃圾回收、Web请求以及数据源用量相关的指标



  • 转载请注明出处:https://oldnoop.tech/c/130.html

Copyright © 2018 oldnoop.tech. All Rights Reserved

鄂ICP备2023022735号-1