zoukankan      html  css  js  c++  java
  • SpringBoot基本配置

    入口类和@SpringBootApplication

      @SpringBootApplication是Spring Boot的核心注解,是一个组合注解,部分源码如下:

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Inherited
    @SpringBootConfiguration
    @EnableAutoConfiguration
    @ComponentScan(excludeFilters = {
    @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
    @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
    public @interface SpringBootApplication 
    
    • 它的核心功能由@EnableAutoConfiguration注解提供,@EnableAutoConfiguration让Spring Boot根据类中的jar包依赖为当前项目进行自动配置
    • Spring Boot会自动扫描@SpringBootApplication注解所在类的同级包以及下级包中的Bean

    关闭特定的自动配置

    通过@SpringBootApplication注解下的exclude参数如:

    @SpringBootApplication(exclude={DataSourceAutoConfigration.class})

     

     

    定制Banner

    Spring Boot启动会有一个默认图案,这个图案 可以自定义, 自定义方式如下

    在src/main/resource下新建一个banner.txt文件

    通过http://patorjk.com/software/taag/这个网站生成字符

    将生成的字符粘贴到banner.txt文件中即可

    关闭banner可以修改入口类

    SpringApplication app = new SpringApplication(DemoApplication.class);
    
        app.setBannerMode(Banner.Mode.OFF);
    
        app.run(args);

     

    starter pom

      Spring Boot提供了很多starter pom方便进行maven配置,下面是一些常见的starter:

      

    名称

    描述

    spring-boot-starter

    核心Spring Boot starter,包括自动配置支持,日志和YAML

    spring-boot-starter-actuator

    生产准备的特性,用于帮我们监控和管理应用

    spring-boot-starter-amqp

    对”高级消息队列协议”的支持,通过spring-rabbit实现

    spring-boot-starter-aop

    对面向切面编程的支持,包括spring-aop和AspectJ

    spring-boot-starter-batch

    对Spring Batch的支持,包括HSQLDB数据库

    spring-boot-starter-cloud-connectors

    对Spring Cloud Connectors的支持,简化在云平台下(例如,Cloud Foundry 和Heroku)服务的连接

    spring-boot-starter-data-elasticsearch

    对Elasticsearch搜索和分析引擎的支持,包括spring-data-elasticsearch

    spring-boot-starter-data-gemfire

    对GemFire分布式数据存储的支持,包括spring-data-gemfire

    spring-boot-starter-data-jpa

    对”Java持久化API”的支持,包括spring-data-jpa,spring-orm和Hibernate

    spring-boot-starter-data-mongodb

    对MongoDB NOSQL数据库的支持,包括spring-data-mongodb

    spring-boot-starter-data-rest

    对通过REST暴露Spring Data仓库的支持,通过spring-data-rest-webmvc实现

    spring-boot-starter-data-solr

    对Apache Solr搜索平台的支持,包括spring-data-solr

    spring-boot-starter-freemarker

    对FreeMarker模板引擎的支持

    spring-boot-starter-groovy-templates

    对Groovy模板引擎的支持

    spring-boot-starter-hateoas

    对基于HATEOAS的RESTful服务的支持,通过spring-hateoas实现

    spring-boot-starter-hornetq

    对”Java消息服务API”的支持,通过HornetQ实现

    spring-boot-starter-integration

    对普通spring-integration模块的支持

    spring-boot-starter-jdbc

    对JDBC数据库的支持

    spring-boot-starter-jersey

    对Jersey RESTful Web服务框架的支持

    spring-boot-starter-jta-atomikos

    对JTA分布式事务的支持,通过Atomikos实现

    spring-boot-starter-jta-bitronix

    对JTA分布式事务的支持,通过Bitronix实现

    spring-boot-starter-mail

    对javax.mail的支持

    spring-boot-starter-mobile

    对spring-mobile的支持

    spring-boot-starter-mustache

    对Mustache模板引擎的支持

    spring-boot-starter-redis

    对REDIS键值数据存储的支持,包括spring-redis

    spring-boot-starter-security

    对spring-security的支持

    spring-boot-starter-social-facebook

    对spring-social-facebook的支持

    spring-boot-starter-social-linkedin

    对spring-social-linkedin的支持

    spring-boot-starter-social-twitter

    对spring-social-twitter的支持

    spring-boot-starter-test

    对常用测试依赖的支持,包括JUnit, Hamcrest和Mockito,还有spring-test模块

    spring-boot-starter-thymeleaf

    对Thymeleaf模板引擎的支持,包括和Spring的集成

    spring-boot-starter-velocity

    对Velocity模板引擎的支持

    spring-boot-starter-web

    对全栈web开发的支持, 包括Tomcat和spring-webmvc

    spring-boot-starter-websocket

    对WebSocket开发的支持

    spring-boot-starter-ws

    对Spring Web服务的支持

     

     

    注:本文是个人学习笔记,以上内容均来自《JavaEE开发的颠覆者 Spring Boot实战》一书

     

     

  • 相关阅读:
    mysql优化三
    mysql优化一
    mysql索引二
    mysql索引
    php连接sql2005
    Android studio 自动导入(全部)包 import (转)
    Android启动页面的正确打开方式 (转载)
    coursera 视频总是缓冲或者无法观看的解决办法(Windows 和 Linux 系统 环境)
    最新解决 Ubuntu16.04 和 win10 双系统时间同步问题 (设置为 UTC 时间)
    2017年12月 六级成绩 留念
  • 原文地址:https://www.cnblogs.com/qiyexue/p/7126300.html
Copyright © 2011-2022 走看看