springboot的特性:
(1)為基于 Spring 的開發提供更快的入門體驗
(2)開箱即用,沒有代碼生成,也無需 XML 配置。同時也可以修改預設值來滿足特 定的需求。
(3)提供了一些大型項目中常見的非功能性特性,如嵌入式伺服器、安全、名額,健 康檢測、外部配置等。
(4)Spring Boot 并不是不對 Spring 功能上的增強,而是提供了一種快速使用 Spring 的方式。
springboot的基本依賴pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ljh.pringboot</groupId>
<artifactId>springboot-01</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath />
</parent>
<!-- 更改jdk版本 -->
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 添加熱部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- servlet,jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- tomcat 的支援. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring-Mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<!-- MySQL驅動 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<!--添加商品springboot的插件 這種方式也可以啟動 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
這些也就是可以在pom.xml中添加的依賴,他們全部繼承與父工程,是以說很友善。
Spring Boot 應用啟動器
spring Boot應用啟動器具體如下:
1)spring-boot-starter 這是Spring Boot的核心啟動器,包含了自動配置、日志和YAML。
2)spring-boot-starter-actuator 幫助監控和管理應用。
3)spring-boot-starter-amqp 通過spring-rabbit來支援AMQP協定(Advanced Message Queuing Protocol)。
4)spring-boot-starter-aop 支援面向方面的程式設計即AOP,包括spring-aop和AspectJ。
5)spring-boot-starter-artemis 通過Apache Artemis 支援 JMS的API(Java Message Service API)。
6)spring-boot-starter-batch 支援Spring Batch,包括HSQLDB資料庫。
7)spring-boot-starter-cache 支援Spring的Cache抽象。
8)spring-boot-starter-cloud-connectors 支援Spring Cloud Connectors,簡化了在像Cloud Foundry或Heroku這樣的雲平台上連接配接服務。
9)spring-boot-starter-data-elasticsearch 支援ElasticSearch搜尋和分析引擎,包括spring-data-elasticsearch。
10)spring-boot-starter-data-gemfire 支援GemFire分布式資料存儲,包括spring-data-gemfire。
11)spring-boot-starter-data-jpa 支援JPA(Java Persistence API),包括spring-data-jpa、spring-orm、hibernate。
12)spring-boot-starter-data-MongoDB 支援MongoDB資料,包括spring-data-mongodb。
13)spring-boot-starter-data-rest 通過spring-data-rest-webmvc,支援通過REST暴露Spring Data資料倉庫。
14)spring-boot-starter-data-solr 支援Apache Solr搜尋平台,包括spring-data-solr。
15)spring-boot-starter-freemarker 支援FreeMarker模闆引擎。
16)spring-boot-starter-groovy-templates 支援Groovy模闆引擎。
17)spring-boot-starter-hateoas 通過spring-hateoas支援基于HATEOAS的RESTful Web服務。
18)spring-boot-starter-hornetq 通過HornetQ支援 JMS。
19)spring-boot-starter-integration 支援通用的spring-integration子產品。
20)spring-boot-starter-jdbc 支援JDBC資料庫。
21)spring-boot-starter-jersey 支援Jersey RESTful Web 服務架構。
22)spring-boot-starter-jta-atomikos 通過Atomikos支援JTA分布式事務處理。
23)spring-boot-starter-jta-bitronix 通過Bitronix支援JTA分布式事務處理。
24)spring-boot-starter-mail 支援javax.mail子產品。
25)spring-boot-starter-mobile 支援spring-mobile。
26)spring-boot-starter-mustache 支援Mustache模闆引擎。
27)spring-boot-starter-Redis 支援Redis鍵值存儲資料庫,包括spring-redis。
28)spring-boot-starter-security 支援spring-security。
29)spring-boot-starter-social-facebook 支援spring-social-facebook
30)spring-boot-starter-social-linkedin 支援pring-social-linkedin
31)spring-boot-starter-social-twitter 支援pring-social-twitter
32)spring-boot-starter-test 支援正常的測試依賴,包括JUnit、Hamcrest、Mockito 以及 spring-test子產品。
33)spring-boot-starter-thymeleaf 支援Thymeleaf模闆引擎,包括與Spring的內建。
34)spring-boot-starter-velocity 支援Velocity模闆引擎。
35)spring-boot-starter-web S支援全棧式Web開發,包括Tomcat和spring-webmvc。
36)spring-boot-starter-websocket 支援WebSocket開發。
37)spring-boot-starter-ws 支援Spring Web Services。
Spring Boot應用啟動器面向生産環境的還有2種,具體如下:
1)spring-boot-starter-actuator 增加了面向産品上線相關的功能,比如測量和監控。
2)spring-boot-starter-remote-shell 增加了遠端ssh shell的支援。
最後,Spring Boot應用啟動器還有一些替換技術的啟動器,具體如下:
1)spring-boot-starter-jetty 引入了Jetty HTTP引擎(用于替換Tomcat)。
2)spring-boot-starter-log4j 支援Log4J日志架構。
3)spring-boot-starter-logging 引入了Spring Boot預設的日志架構Logback。
4)spring-boot-starter-tomcat 引入了Spring Boot預設的HTTP引擎Tomcat。
5)spring-boot-starter-undertow 引入了Undertow HTTP 引擎(用于替換Tomcat)。
springboot相對于ssm提供了一種更加友善簡潔的方式。
ssm需要大量的依賴以及配置檔案,看下面的連結就知道了,而springboot需要添加的依賴特别少,因為他繼承了一個父工程,并且也不需要對父工程進行管理,在配置檔案方面,springboot隻需要寫一個application.properties或者application.yml即可,application.yml隻有在idea中才能生效,對于eclipse或者MyEclipse是不管用的。
ssm架構的整合
再對比springboot項目的目錄:
application.properties配置檔案基本需要配置以下資訊:
#修改tomcat端口号
server.port=8080
#修改項目的通路路徑
server.context-path=/
#自定義資訊
user=ljh
#配置多環境 激活指定的配置檔案 dev是我配置檔案名的字尾application-dev.properties
#spring.profiles.active=dev
#配置視圖解析器
spring.mvc.view.prefix= /WEB-INF/views/
spring.mvc.view.suffix= .jsp
#配置資料源
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
#配置加載xml檔案和pojo
mybatis.type-aliases-package=com.ljh.pojo
mybatis.mapperLocations=classpath:mapper/*.xml
#設定日志級别
logging.level.cn.yanqi=DEBUG
logging.level.org.springframework=DEBUG
常用的也就是上面幾種,當然還有很多可以配置的資訊。
springboot的注解:
@SpringBootApplication: 啟動類注解
也可以是這種形式,@SpringBootApplication(scanBasePackages = {“com.ljh.*”}) 這樣可以掃描該路徑下所有的controller。
@MapperScan(“com.ljh.mapper”) 指定所掃的包,會自動掃描指定包下的全部标有@Component的類,并注冊成bean,這個注解是在springboot整合mybatis時使用的 也是放在啟動類中使用。
@RestController 這個注解它裡面包含了 @Controller 和 @ResponseBody 。
@GetMapping 裡面包含了 @RequestMapping+method=RequestMethod.GET) ,就相當于 @RequestMapping(value="/queryall",method=RequestMethod.GET)。這些是springboot特有的注解.
關于spring和springmvc的注解
spring面試題
springmvc面試題