Springboot
Springboot简历
SPringleboot特性
Spingboot pom.xml
Spring Boot核心功能
独立运行的Spring项目:Spring Boot可以以jar包的形式独立运行,运行一个Spring Boot项目只需通过java -jar xx.jar来运行
内嵌的Servlet容器:Spring Boot可选择内嵌Tomcat、Jetty,无需以war包形式部署项目
提供starter简化Maven的配置,如使用spring-boot-starter-web时,会自动加入tomcat,webMvc,jackson,hibernate-validate的jar
自动配置Spring:Spring Boot 会根据在类路径中的jar包,类为jar包里的类自动配置Bean
准生产级别的应用监控:Spring Boot提供了基于http,ssh,telnet对运行时的项目进行监控
无代码生产和xml配置(spring 4.x中通过条件注解实现)
Spring Boot的项目打包方式:jar,父工程:spring-boot-start-parent,依赖:spring-boot-starter-web,maven插件spring-boot-maven-plugin
入口类:AnhuiApplication为应用程序入口类,在com.pingan.anhui包下,其他项目必须在其子包内.
启动方式:运行AnhuiApplication的main方法,或者通过springboot的maven插件
全局配置文件:application.properties(或者application.yml)
Spring Boot的核心
基本配置:
入口类和@SpringBootApplication注解:
入口类中有个main方法,它是标准的Java应用入口方法,用于启动Spring Boot项目,@SpringBootApplication是Spring Boot的核心注解,它是一个组合注解:包括了@SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan注解,其中@SpringBootConfiguration就是@Configuration配置类注解,@EnableAutoConfiguration是根据类路径配置的jar包依赖开自动配置的注解。
如:添加spring-boot-starter-web时,会自动加入tomcat,SpringMVC的依赖,并且对Tomcat和Spring MVC进行自动配置,Spring Boot会自动扫描@SpringBootApplication 所在类的同级包及以下包 的Bean,建议其他所有包都在@SpringBootApplication 所在包的子包里。
关闭自动配置:
Spring Boot使用一个全局的配置文件application.properties或者application.yml,放置在src/main/resources/下或者类路径的config下,我们可以通过在全局配置文件中对一些默认配置的配置值进行修改
starter pom的使用
Spring Boot为我们提供了简化企业级开发的绝大多数常见的starter pom,只要使用了应用场景所需的相关starter pom,就可以消除相关技术的配置得到Spring Boot为我们自动配置好的Bean。
spring Boot官方提供了很多的starter pom
spring-boot-starter springboot核心starter ,包括自动配置,日志,yaml配置文件的支持
spring-boot-starter-actuator 准生产特性,用来监控和管理应用
spring-boot-starter-remote-shell 提供基于ssh协议的监控和管理
spring-boot-starter-amqp 使用spring-rabbit支持AMQP
spring-boot-starter-aop 使用AOP和AspectJ支持面向切面编程
spring-boot-starter-batch 对springBatch支持
spring-boot-starter-cache 对SpringCache抽象的支持
spring-boot-starter-cloud-connectors 对云平台(Cloud Foundry ,Heroku)提供的服务简化的连接方式
spring-boot-starter-data-elasticsearch 对spring-data-elasticsearch的支持
spring-boot-starter-data-gemfire 对分布式存储GemFire的支持
spring-boot-starter-data-jpa 对jpa的支持,包括spring-data-jap,spring-orm,Hibernate
spring-boot-starter-data-mongodb 通过spring-data-mongodb对mongodb的支持
spring-boot-starter-data-rest 通过spring-data-rest-webmvc对spring Data reposity暴露为REST形式的服务
spring-boot-starter-data-solr 通过spring-data-solr对Apache Solr的支持
spring-boot-starter-data-freemaker 对Freemaker的支持
spring-boot-starter-data-groovy-templates 对Groovy模版引擎的支持
spring-boot-starter-hateoas 通过spring-hateoas对基于HATEOAS的REST形式的网络服务的支持
spring-boot-starter-hornetq 通过HornetQ对JMS的支持
spring-boot-starter-integration 对系统集成框架spring-integration的支持
spring-boot-starter-jdbc 对JDBC数据库的支持
spring-boot-starter-jersey 对Jersey REST形式的网络服务的支持
spring-boot-starter-jta-atomikos 通过Atomikos对分布式事物的支持
spring-boot-starter-jta-bitronix 通过Bitronix对分布式事物的支持
spring-boot-starter-mail 对spring 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 对facebook的支持
spring-boot-starter-social-twitter 通过spring-social-twitter 对twitter的支持
spring-boot-starter-social-linkedin 通过spring-social-linkedin 对linkedin的支持
spring-boot-starter-thymeleaf 对Thymeleaf模版引擎的支持,包含于spring的整合配置
spring-boot-starter-velocity 对velocity模版引擎的支持
spring-boot-starter-web 对web项目开发的支持,包含tomcat和spring-webmvc
spring-boot-starter-Tomcat springboot默认容器tomcat
spring-boot-starter-Jetty jetty容器
spring-boot-starter-undertow Undertow容器
spring-boot-starter-logging 默认日志输出框架Logback
spring-boot-starter-log4j 支持log4j
spring-boot-starter-websocket websocket的支持
spring-boot-starter-ws spring webservice的支持
使用xml配置
Spring Boot提倡零配置,即无xml配置,但是有些特殊要求我们必须使用xml配置,我们可以通过@ImportResouce来加载xml配置
外部配置:
命令行参数配置:
Spring Boot基于jar包运行,打成jar包的程序可以直接通过下面命令运行:
常规属性配置:
常规Spring环境下,注入properties文件的值,通过@PropertySource指明properties文件的位置,通过@Value注入值
在Spring Boot里,如果在application.properties定义属性,可以使用@Value注解注入即可。
Profile的配置:
Profile是Spring支持不同环境应对不同配置,全局的Profile配置使用:
application-{profile}.properties文件(如application-dev.properties),然后在application.properties文件中添加属性:
spring.profiles.active = dev来指定活动的Profile
4.SpringBoot的运行原理
SpringBoot的运行原理
自定义starter pom
待续................
提供基于ssh协议的监控和管理