一:spring的介紹html
Spring是一個開源框架,它由Rod Johnson建立。它是爲了解決企業應用開發的複雜性而建立的。前端
它是一個容器框架,用來裝javabean(java對象),中間層框架(萬能膠)能夠起一個鏈接做用,好比說把Struts和hibernate粘合在一塊兒運用。簡單來講,Spring是一個輕量級的控制反轉(IoC)和麪向切面(AOP)的容器框架。java
二:spring bootnode
1. Spring Boot簡介
Spring 誕生時是 Java 企業版(Java Enterprise Edition,JEE,也稱 J2EE)的mysql
輕量級代替品。無需開發重量級的 Enterprise JavaBean(EJB),Spring 爲企業級git
Java 開發提供了一種相對簡單的方法,經過依賴注入和麪向切面編程,用簡單的Java 對象(Plain Old Java Object,POJO)實現了 EJB 的功能。github
雖然 Spring 的組件代碼是輕量級的,但它的配置倒是重量級的。web
第一階段:xml配置redis
在Spring 1.x時代,使用Spring開發滿眼都是xml配置的Bean,隨着項目的擴大,咱們須要把xml配置文件放到不一樣的配置文件裏,那時須要頻繁的在開發的類和配置文件之間進行切換spring
第二階段:註解配置
在Spring 2.x 時代,隨着JDK1.5帶來的註解支持,Spring提供了聲明Bean的註解(例如@Component、@Service),大大減小了配置量。主要使用的方式是應用的基本配置(如數據庫配置)用xml,業務配置用註解
第三階段:java配置
Spring 3.0 引入了基於 Java 的配置能力,這是一種類型安全的可重構配置方式,能夠代替 XML。咱們目前恰好處於這個時代,Spring4.x和Spring Boot都推薦使用Java配置。
全部這些配置都表明了開發時的損耗。 由於在思考 Spring 特性配置和解決業務問題之間須要進行思惟切換,因此寫配置擠佔了寫應用程序邏輯的時間。除此以外,項目的依賴管理也是件吃力不討好的事情。決定項目裏要用哪些庫就已經夠讓人頭痛的了,你還要知道這些庫的哪一個版本和其餘庫不會有衝突,這難題實在太棘手。而且,依賴管理也是一種損耗,添加依賴不是寫應用程序代碼。一旦選錯了依賴的版本,隨之而來的不兼容問題毫無疑問會是生產力殺手。
Spring Boot 讓這一切成爲了過去。
Spring Boot 簡化了基於Spring的應用開發,只須要「run」就能建立一個獨立的、生產級別的Spring應用。Spring Boot爲Spring平臺及第三方庫提供開箱即用的設置(提供默認設置),這樣咱們就能夠簡單的開始。多數Spring Boot應用只須要不多的Spring配置。
咱們可使用SpringBoot建立java應用,並使用java –jar 啓動它,或者採用傳統的war部署方式。
Spring Boot 主要目標是:
l 爲全部 Spring 的開發提供一個從根本上更快的入門體驗
l 開箱即用,但經過本身設置參數,便可快速擺脫這種方式。
l 提供了一些大型項目中常見的非功能性特性,如內嵌服務器、安全、指標,健康檢測、外部化配置等
l 絕對沒有代碼生成,也無需 XML 配置。
2. Spring Boot 入門
2.1. 環境準備
數據庫:MySQL
IDE:Eclipse Mars2
Spring-Boot:1.4.4
Maven: 3.3.3 (官方聲明1.4.4版本須要Maven 3.2+)
本地倉庫:須要使用資料中的倉庫
2.2. 起步依賴
2.2.1. 建立一個Maven工程
2.2.2. 添加依賴
在pom.xml中添加依賴,效果以下
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<groupId>cn.itcast.springboot</groupId>
<artifactId>itcast-springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
咱們會驚奇地發現,咱們的工程自動添加了好多好多jar 包,而這些jar 包正式咱們作開發時須要導入的jar 包。
由於這些jar 包被咱們剛纔加入的spring-boot-starter-web 所引用了,因此添加spring-boot-starter-web後會自動把依賴傳遞過來。
2.3. 變動JDK版本
咱們發現默認狀況下工程的JDK版本是1.6,可是一般使用的是1.7的版本
修改JDK爲1.7,須要在pom.xml中添加如下配置:
<properties>
<java.version>1.7</java.version>
</properties>
使用Maven更新工程後,就發現版本已經變成1.8了
注意:
雖然JDK1.6或者1.7均可以使用Spring-Boot,但Spring-Boot官方建議使用JDK1.8。要使用JDK1.8,首先必需要配置JDK1.8後,纔可使用上述方法設置。
2.4. 引導類
須要建立一個引導類:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demo {
public static void main(String[] args) {
SpringApplication.run(Demo.class, args);
}
}
這裏多了一個@SpringBootApplication註解
@Configuration: 用於定義一個配置類
@EnableAutoConfiguration :Spring Boot 會自動根據你jar 包的依賴來自動配置
項目。
@ComponentScan: 告訴Spring 哪一個packages 的用註解標識的類會被spring
自動掃描而且裝入bean 容器。
Banner
直接啓動,控制檯出現如下標識。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.4.RELEASE)
這個標識是Spring啓動標識,若是不想要,能夠設置取消
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
// SpringApplication.run(Application.class, args);
SpringApplication application = new SpringApplication(Application.class);
application.setBannerMode(Mode.OFF);
application.run(args);
}
}
參考附錄二的banner設置,能夠經過修改配置文件制定本身的標識。
2.5. 入門程序
需求:使用Spring MVC實現Hello World輸出
2.5.1. 原來的實現
咱們如今開始使用spring MVC 框架,實現json 數據的輸出。若是按照咱們原來的作法,須要在web.xml 中添加一個DispatcherServlet 的配置,還須要添加一個spring的配置文件,配置文件以下配置
spring加入配置
<!-- controller註解掃描 -->
<context:component-scan base-package="cn.itcast.springboot.controller" />
<!-- 註解驅動 -->
<mvc:annotation-driven />
web.xml加入配置
<!-- 配置前端控制器 -->
<servlet>
<servlet-name> itcast-springboot</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/*.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name> itcast-springboot</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
還要編寫Controller。。。
2.5.2. Spring-Boot的實現
咱們不須要配置文件,直接編寫Controller類便可
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@RequestMapping("info")
public String info() {
return "Hello world!";
}
}
@RestController註解:其實就是@Controller和@ResponseBody註解加在一塊兒
啓動方式一:啓動以前編寫的引導類便可
啓動方式二:使用Maven命令spring-boot:run執行便可
選擇 Maven Build
在瀏覽器地址欄輸入http://localhost:8080/info 便可看到運行結果
2.6. 熱部署
咱們在開發中反覆修改類、頁面等資源,每次修改後都是須要從新啓動才生效,這樣每次啓動都很麻煩,浪費了大量的時間。
能不能在我修改代碼後不重啓就能生效呢?能夠,因爲Spring Boot應用只是普通的Java應用,因此JVM熱交換(hot-swapping)也能開箱即用。不過JVM熱交換能替換的字節碼有限制,想要更完全的解決方案可使用Spring Loaded項目或JRebel。 spring-boot-devtools 模塊也支持應用快速重啓(restart)。
咱們只須要在pom.xml加入以下配置便可
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
3. SpringBoot整合
3.1. 整合Spring Data JPA
3.1.1. 需求
使用Spring Boot + Spring MVC + Spring Data JPA + EasyUI 框架組合實現部門列表查詢,效果以下:
3.1.2. 環境準備
3.1.2.1. 導入數據庫表
在MySQL數據庫執行如下語句
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) DEFAULT NULL COMMENT '用戶名',
`password` varchar(100) DEFAULT NULL COMMENT '密碼',
`name` varchar(100) DEFAULT NULL COMMENT '姓名',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
INSERT INTO `user` VALUES ('1', 'zhangsan', '123456', '張三');
INSERT INTO `user` VALUES ('2', 'lisi', '123456', '李四');
INSERT INTO `user` VALUES ('3', 'wangwu', '123456', '王五');
INSERT INTO `user` VALUES ('4', 'zhangwei', '123456', '張偉');
INSERT INTO `user` VALUES ('5', 'lina', '123456', '李娜');
INSERT INTO `user` VALUES ('6', 'lilei', '123456', '李磊');
3.1.2.2. 建立Maven工程
itcast-info(打jar包),在pom.xml中進行以下配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
3.1.2.3. 加入Spring-Boot配置文件
在src/main/resources 下添加application.properties 配置文件,內容以下:
#DB Configuration:
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/taotao
spring.datasource.username=root
spring.datasource.password=root
#JPA Configuration:
spring.jpa.database=MySQL
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
此文件用於覆蓋Spring Boot的默認配置,完整的配置信息參考「附錄2」
3.1.3. 後端實現
3.1.3.1. 建立實體類
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class User {
@Id
private Long id;
private String userName;
private String password;
private String name;
//添加 get 和set 方法
}
3.1.3.2. 建立DAO接口
import org.springframework.data.jpa.repository.JpaRepository;
import cn.itcast.info.pojo.User;
public interface UserDao extends JpaRepository<User, Long> {
}
3.1.3.3. 建立業務邏輯接口
import java.util.List;
import cn.itcast.info.pojo.User;
public interface UserService {
List<User> findAll();
}
3.1.3.4. 建立業務邏輯實現類
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.itcast.info.dao.UserDao;
import cn.itcast.info.pojo.User;
import cn.itcast.info.service.UserService;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public List<User> findAll() {
List<User> list = this.userDao.findAll();
return list;
}
}
3.1.3.5. 建立Controller
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.itcast.info.pojo.User;
import cn.itcast.info.service.UserService;
@RestController
@RequestMapping("user")
public class UserControlelr {
@Autowired
private UserService userService;
@RequestMapping("list")
public List<User> queryUserAll() {
List<User> list = this.userService.findAll();
return list;
}
}
3.1.3.6. 建立引導類
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
運行引導類Application,打開瀏覽器輸入http://127.0.0.1:8080/user/list
3.1.4. 前端實現
把資料中的static文件夾,拷貝到src/main/resources路徑下
瀏覽器地址欄輸入:http://127.0.0.1:8080/user.html,效果以下
運行引導類Application
3.2. 整合MyBatis
3.2.1. 簡單整合
3.2.1.1. 加入依賴
在pom.xml中加入如下依賴
<!-- SpringBoot的Mybatis啓動器 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
3.2.1.2. 編寫Mapper
和以前的方式同樣,只是多了兩個註解
@Mapper:聲明Mapper接口
@Select:聲明這個接口所須要使用的sql,固然,有查詢的註解,確定就有增刪改的註解。
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import cn.itcast.info.pojo.User;
@Mapper
public interface UserMapper {
@Select("select * from user where name like '%${value}%'")
public List<User> queryUserByName(String name);
}
3.2.1.3. 編寫Service和Controller
添加Service調用Mapper
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Autowired
private UserMapper userMapper;
@Override
public List<User> findAll() {
List<User> list = this.userDao.findAll();
return list;
}
@Override
public List<User> queryUserByName(String name) {
List<User> list = this.userMapper.queryUserByName(name);
return list;
}
}
修改Controller
@RestController
@RequestMapping("user")
public class UserControlelr {
@Autowired
private UserService userService;
@RequestMapping("list")
public List<User> queryUserAll() {
List<User> list = this.userService.findAll();
return list;
}
@RequestMapping("list/{name}")
public List<User> queryUserAll(@PathVariable String name) {
List<User> list = this.userService.queryUserByName(name);
return list;
}
}
3.2.1.4. 測試
瀏覽器地址欄輸入:http://127.0.0.1:8080/user/list/張
顯示效果:
3.2.2. 整合通用Mapper和分頁助手
以上全部的配置都是使用的默認配置,咱們只須要專一java代碼的開發便可,不須要加入配置文件了。
但並非全部得場景都是簡單的業務,有時候業務複雜,須要咱們加入自定義的配置文件;有時候須要載入例如分頁助手這樣的插件,輔助開發,因此咱們也須要了解如何加載這些配置。
3.2.2.1. 加入依賴
咱們須要加入通用Mapper和分頁插件,因此須要在pom.xml加入如下依賴
<!-- 通用Mapper -->
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>mapper</artifactId>
<version>2.3.4</version>
</dependency>
<!-- 分頁助手 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.7.5</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>0.9.1</version>
</dependency>
3.2.2.2. 修改配置文件
在application.properties添加配置
#spring集成Mybatis環境
#pojo別名掃描包
mybatis.type-aliases-package=cn.itcast.info.pojo
#加載Mybatis核心配置文件
mybatis.mapper-locations=classpath:mapper/*Mapper.xml
mybatis.config-location=classpath:mybatis/SqlMapConfig.xml
#配置鏈接池,還須要在pom.xml中加入該鏈接池的依賴
#spring.datasource.type=com.jolbox.bonecp.BoneCPDataSource
在src\main\resources\mapper路徑下加入UserMapper.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.itcast.info.dao.UserMapper">
<select id="queryAll" resultType="user">
select * from user
</select>
</mapper>
在src\main\resources\mybatis加入SqlMapConfig.xml配置文件,用以加載通用Mapper和分頁助手
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 分頁助手 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql" />
<!-- 該參數默認爲false -->
<!-- 設置爲true時,使用RowBounds分頁會進行count查詢 -->
<property name="rowBoundsWithCount" value="true" />
</plugin>
<!-- 通用Mapper -->
<plugin interceptor="com.github.abel533.mapperhelper.MapperInterceptor">
<!--主鍵自增回寫方法,默認值MYSQL,詳細說明請看文檔 -->
<property name="IDENTITY" value="MYSQL" />
<!--通用Mapper接口,多個通用接口用逗號隔開 -->
<property name="mappers" value="com.github.abel533.mapper.Mapper" />
</plugin>
</plugins>
</configuration>
3.2.2.3. 編寫Mapper
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import cn.itcast.info.pojo.User;
//extends com.github.abel533.mapper.Mapper<User>:須要繼承通用Mapper
@Mapper
public interface UserMapper extends com.github.abel533.mapper.Mapper<User> {
@Select("select * from user where name like '%${value}%'")
public List<User> queryUserByName(String name);
// 使用UserMapper.xml配置文件
public List<User> queryAll();
}
3.2.2.4. 編寫Service和Controller
Service編寫
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import cn.itcast.info.dao.UserDao;
import cn.itcast.info.dao.UserMapper;
import cn.itcast.info.pojo.User;
import cn.itcast.info.service.UserService;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Autowired
private UserMapper userMapper;
@Override
public List<User> findAll() {
List<User> list = this.userDao.findAll();
return list;
}
@Override
public List<User> queryUserByName(String name) {
List<User> list = this.userMapper.queryUserByName(name);
return list;
}
// 調用使用UserMapper.xml的Mapper
@Override
public List<User> queryAll() {
List<User> list = this.userMapper.queryAll();
return list;
}
// 使用通用Mapper和分頁助手
@Override
public List<User> queryUserByPage(Integer page, Integer rows) {
// 設置分頁
PageHelper.startPage(page, rows);
// 使用通用Mapper的方法進行查詢全部數據
List<User> list = this.userMapper.select(null);
return list;
}
}
Controller編寫
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.itcast.info.pojo.User;
import cn.itcast.info.service.UserService;
@RestController
@RequestMapping("user")
public class UserControlelr {
@Autowired
private UserService userService;
@RequestMapping("list")
public List<User> queryUserAll() {
List<User> list = this.userService.findAll();
return list;
}
@RequestMapping("list/{name}")
public List<User> queryUserAll(@PathVariable String name) {
List<User> list = this.userService.queryUserByName(name);
return list;
}
@RequestMapping("list/query")
public List<User> queryUserAll2() {
List<User> list = this.userService.queryAll();
return list;
}
@RequestMapping("list/{page}/{rows}")
public List<User> queryUserAll(@PathVariable Integer page, @PathVariable Integer rows) {
List<User> list = this.userService.queryUserByPage(page, rows);
return list;
}
}
3.2.2.5. 測試
測試使用UserMapper.xml
瀏覽器地址欄輸入:http://127.0.0.1:8080/user/list/query
測試使用通用Mapper和分頁助手
瀏覽器地址欄輸入:http://127.0.0.1:8080/user/list/2/2
3.3. 整合Redis
3.3.1. 註解方式實現添加緩存
需求:基於上例代碼,將列表數據緩存到Redis
3.3.1.1. 加入依賴
在pom.xml加入依賴
<!-- 配置使用redis啓動器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
3.3.1.2. 修改引導類
修改開啓緩存,添加註解@EnableCaching
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
3.3.1.3. 設置實現序列化接口
須要修改實體,讓實體實現序列化接口
@Entity
public class User implements Serializable {
@Id
private Long id;
private String userName;
private String password;
private String name;
。。。。。。
}
3.3.1.4. 實現添加/刪除緩存
修改UserServiceImpl,添加@Cacheable註解實現緩存添加
@Override
@Cacheable(value = "userCache", key = "'user.findAll'")
public List<User> findAll() {
System.out.println("從Mysql中查詢");
List<User> list = this.userDao.findAll();
return list;
}
@Override
@CacheEvict(value = "userCache", key = "'user.findAll'")
public List<User> queryUserByName(String name) {
System.out.println("緩存清理了!");
List<User> list = this.userMapper.queryUserByName(name);
return list;
}
這樣設置完成後,執行findAll()方法就會使用緩存,若是緩存沒有就添加緩存,而queryUserByName(String name)方法則是刪除緩存
@Cacheable:添加/使用緩存
@CacheEvict:刪除緩存
參數value是緩存的名字,在執行的時候,會找叫這個名字的緩存使用/刪除
參數key默認狀況下是空串」」,是Spring的一種表達式語言SpEL,咱們這裏能夠隨意指定,可是須要注意必定要加單引號
3.3.2. redis的深刻使用
3.3.2.1. 直接操做redis
redis除了做爲緩存使用,還有不少其餘的做用,例如利用redis的單線程獲取惟一數,例如使用redis爲單點登陸系統存儲用戶登陸信息等,咱們就須要直接操做redis。
官網提供了三種接口RedisConnectionFactory, StringRedisTemplate 和 RedisTemplate,咱們能夠直接注入或者本身實現其餘的實現類,來直接操做redis。咱們這裏使用RedisTemplate來操做Redis。
以下所示,咱們只須要直接注入RedisTemplate便可使用如下方法操做redis的五種不一樣的數據類型
測試:
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Override
@CacheEvict(value = "userCache", key = "'user.findAll'")
public List<User> queryUserByName(String name) {
// 保存數據
this.redisTemplate.boundValueOps("redis").set("Hello redis !");
// 設置有效時間爲100秒
this.redisTemplate.boundValueOps("redis").expire(100l, TimeUnit.SECONDS);
// 給value每次執行加一操做
this.redisTemplate.boundValueOps("count").increment(1l);
System.out.println("緩存清理了!");
List<User> list = this.userMapper.queryUserByName(name);
return list;
}
3.3.2.2. 設置redis鏈接屬性
redis單機版
redis啓動器默認狀況下會找本地的redis服務,端口號默認是6379若是須要訪問其餘服務器的redis,則須要在application.properties中進行以下配置:
#Redis
spring.redis.host=192.168.37.161
spring.redis.port=6379
這表示會去找ip爲192.168.37.161和端口爲6379的服務
redis集羣版
#Redis
#spring.redis.host=192.168.37.161
#spring.redis.port=6379
#Redis Cluster
spring.redis.cluster.nodes=192.168.37.161:7001,192.168.37.161:7002,192.168.37.161:7003,192.168.37.161:7004,192.168.37.161:7005,192.168.37.161:7006
切換到集羣版只須要作以上配置,配置集羣版節點信息,註釋掉單機版信息
3.4. 整合ActiveMQ
3.4.1. 加入依賴
在pom.xml中加入如下配置
<!-- 配置ActiveMQ啓動器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
3.4.2. 建立隊列
在引導類中添加如下方法,設置隊列
@SpringBootApplication
@EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public Queue queue() {
return new ActiveMQQueue("itcast.queue");
}
}
3.4.3. 發送消息
編寫Controller,發送消息
import javax.jms.Destination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("queue")
public class QueueController {
//注入發送消息的對象
@Autowired
private JmsTemplate jmsTemplate;
//注入消息隊列
@Autowired
private Destination destination;
//編寫發送消息的方法
@RequestMapping("send/{message}")
public String send(@PathVariable String message) {
this.jmsTemplate.convertAndSend(destination, message);
return "消息發送成功!消息內容:" + message;
}
}
3.4.4. 接收消息
編寫bean,加入@Component註解讓spring管理這個bean,做爲接收消息的消費者
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
@Component
public class Consumer {
// 接受消息方法
@JmsListener(destination = "itcast.queue")
public void readMessage(String text) {
System.out.println("接受到的消息是:" + text);
}
}
測試:
啓動服務後,在瀏覽器執行http://127.0.0.1:8080/queue/send/發消息了11
便可看到消息發送成功
同時能夠在控制檯看到打印信息
咱們沒有安裝ActiveMQ,爲何可使用?由於Spring Boot 內置了ActiveMQ 的服務,因此咱們不用單獨啓動也能夠實現消息的發送和接收。
3.4.5. 使用外部服務
首先確認有一臺外部ActiveMQ服務可使用
在application.properties中加入如下配置
#ActiveMQ
spring.activemq.broker-url=tcp://192.168.37.161:61616
這樣就加入了ActiveMQ服務的地址
3.5. 整合junit
3.5.1. 加入依賴
在pom.xml中加入測試依賴
<!-- 配置測試啓動器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
3.5.2. 編寫測試類
import javax.jms.Destination;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import cn.itcast.info.Application;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class MessageTest {
@Autowired
private Destination destination;
@Autowired
private JmsTemplate jmsTemplate;
@Test
public void test() {
System.out.println("我發消息了!");
this.jmsTemplate.convertAndSend(destination, "Hello ActiveMQ!");
}
}
SpringRunner 與SpringJUnit4ClassRunner 是繼承關係,可是沒有不一樣的地方,只是看起來子類SpringRunner要短一些而已。
@SpringBootTest 註解的class 屬性要指定引導類的class
3.6. 整合dubbox
3.6.1. 環境準備
3.6.1.1. dubbox
dubbo是一個分佈式的服務架構,可直接用於生產環境做爲SOA服務框架。官網首頁:http://dubbo.io/
淘寶將這個項目開源出來之後,獲得了很多同行的支持,包括:
噹噹網的擴展版本dubbox :https://github.com/dangdangdotcom/dubbox
京東的擴展版本jd-hydra: http://www.oschina.NET/p/jd-hydra
不過,略有遺憾的是, dubbo因爲某些緣由致使dubbo團隊已經解散,已經很牛沒有更新了,反到是噹噹網的擴展版本仍在持續發展。由於dubbox支持更新的spring版本,因此咱們使用dubbox。
Dubbox在maven中央倉庫並無對應的依賴,因此咱們須要本身動手將其發佈到咱們的本地倉庫來使用。
使用git從碼雲上把dubbox的代碼clone下來,
地址:https://git.oschina.net/wuyu15255872976/dubbox.git
執行Maven命令把工程安裝到本地倉庫
命令:clean install -Dmaven.test.skip
課程資料提供的倉庫已經安裝好了,能夠直接使用
3.6.1.2. spring-boot-starter-dubbo
咱們之前在使用dubbo的時候都是用的xml配置。而在整合Spring Boot的時候可使用@ImportResource註解來引入的dubbo的xml配置。
可是Spring Boot自己並不推薦xml配置。怎麼解決這個矛盾,咱們能夠本身準備一個Spring Boot Starter dubbo的項目來引導Spring Boot對Dubbo的自動化配置。已經有人開發好了這個自動化配置項目,咱們直接使用就好了
使用git從碼雲上把spring-boot-starter-dubbo的代碼clone下來,
地址:https://git.oschina.net/wuyu15255872976/spring-boot-starter-dubbo.git
執行Maven命令把工程安裝到本地倉庫
命令:clean install -Dmaven.test.skip
爲了統一管理,把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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.4.4.RELEASE</version>
<name>Spring Boot Dubbo Rpc</name>
<description>Spring Boot Dubbo Rpc</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.8.5-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- zookeeper 客戶端 -->
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.4.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
課程資料提供的倉庫已經安裝好了,能夠直接使用
3.6.1.3. zookeeper註冊中心
咱們使用zookeeper做爲dubbo的註冊中心。
這裏使用的zookeeper註冊中心地址是:192.168.37.161:2181
修改hosts,配置註冊中心的域名是zookeeper.taotao.com
3.6.2. 搭建項目
taotao-parent做爲全部工程的父工程
taotao- interface做爲提供pojo和抽取服務接口的
taotao-provider做爲服務提供者
taotao-consumer做爲服務消費者
3.6.2.1. 搭建taotao-parent
建立taotao-parent,並打pom包,這裏配置公共使用的依賴。
修改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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<!-- 配置java版本 -->
<java.version>1.7</java.version>
</properties>
<dependencies>
<!-- 配置測試啓動器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 配置web啓動器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency>
<!-- 配置dubbo啓動器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.4.4.RELEASE</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
3.6.2.2. 搭建taotao-interface
建立taotao-interface,並打jar包。
修改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>
<parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
3.6.2.3. 搭建taotao-provider
建立taotao-provider,並打jar包。
修改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>
<parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- 加入taotao-interface依賴 -->
<dependency>
<groupId>com.taotao</groupId>
<artifactId>taotao-interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 配置MyBatis啓動器 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!-- MySQL鏈接驅動 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>
3.6.2.4. 搭建taotao-consumer
建立taotao-consumer,並打jar包。
修改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>
<parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- 加入taotao-interface依賴 -->
<dependency>
<groupId>com.taotao</groupId>
<artifactId>taotao-interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
3.7. 實現功能
3.7.1. 實現taotao-interface
編寫pojo
import java.io.Serializable;
public class User implements Serializable {
private Long id;
private String userName;
private String password;
private String name;
get/set方法
}
編寫Service接口
import com.taotao.common.pojo.User;
public interface UserService {
public User queryUserById(Long id);
}
3.7.2. 實現taotao-provider
編寫UserMapper
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.taotao.common.pojo.User;
@Mapper
public interface UserMapper {
@Select("select * from user where id=#{id}")
public User queryUserById(Long id);
}
編寫UserServiceImpl實現類
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import com.taotao.common.consumer.UserService;
import com.taotao.common.pojo.User;
import com.taotao.mapper.UserMapper;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User queryUserById(Long id) {
User user = this.userMapper.queryUserById(id);
return user;
}
}
編寫引導類
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.alibaba.boot.dubbo.EnableDubboAutoConfiguration;
@SpringBootApplication
@EnableDubboAutoConfiguration
public class ProviderApplication {
public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args);
}
}
在src/main/resources加入配置文件application.properties
#DB Configuration:
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/taotao
spring.datasource.username=root
spring.datasource.password=root
#配置服務器訪問端口號
server.port=8081
#配置dubbo信息
#配置服務名稱
spring.dubbo.application.name=taotao-provider
#註冊中心類型
spring.dubbo.registry.protocol=zookeeper
#註冊中心鏈接方式
spring.dubbo.registry.address=manager.taotao.com:2181
#配置服務調用所使用的協議
spring.dubbo.protocol.name=dubbo
#配置服務端口號
spring.dubbo.protocol.port=20880
#配置服務訪問地址
spring.dubbo.protocol.host=localhost
#配置dubbo掃描
spring.dubbo.scan=com.taotao.provider
3.7.3. 實現taotao-consumer
編寫Controller
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.taotao.common.consumer.UserService;
import com.taotao.common.pojo.User;
@RestController
@RequestMapping("user")
public class UserController {
@Reference
private UserService userService;
@RequestMapping("{id}")
public User queryUserById(@PathVariable Long id) {
User user = this.userService.queryUserById(id);
return user;
}
}
編寫引導類
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.alibaba.boot.dubbo.EnableDubboAutoConfiguration;
@SpringBootApplication
@EnableDubboAutoConfiguration
public class ConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
在src/main/resources加入配置文件application.properties
#配置服務器訪問端口號
server.port=8080
#配置dubbo信息
#配置服務名稱
spring.dubbo.application.name=taotao-consumer
#註冊中心類型
spring.dubbo.registry.protocol=zookeeper
#註冊中心鏈接方式
spring.dubbo.registry.address=manager.taotao.com:2181
#配置服務調用所使用的協議
spring.dubbo.protocol.name=dubbo
#配置服務端口號
spring.dubbo.protocol.port=20880
#配置服務訪問地址
spring.dubbo.protocol.host=localhost
#配置dubbo掃描
spring.dubbo.scan=com.taotao.consumer
4. Spring Boot深刻學習
4.1. 讀取配置文件
4.1.1. .讀取核心配置文件
在工程的src/main/resources 下修改核心配置文件
application.properties, 添加內容以下
name=傳智播客
url=http://www.itcast.cn
在Controller中添加:
@Resource
private Environment env;
@RequestMapping("list")
public List<User> queryUserAll() {
System.out.println(env.getProperty("name"));
System.out.println(env.getProperty("url"));
List<User> list = this.userService.findAll();
return list;
}
就能夠直接把配置文件信息打印出來。
注意包名是:org.springframework.core.env.Environment
4.1.2. 讀取自定義文件
在工程的src/main/resources 下構建自定義配置文件mail.properties, 內容以下
mail.host=smtp.sina.com
mail.port=25
mail.username=itcast
mail.password=heima
編寫JavaBean
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(locations = "classpath:mail.properties", prefix = "mail")
public class MailProperties {
private String host;
private Integer port;
private String username;
private String password;
set/get
}
改造Controller
@Autowired
private MailProperties mailProperties;
@RequestMapping("/mailInfo")
public String mailInfo() {
return mailProperties.getHost() + "<br>" + mailProperties.getPort() + "<br>" + mailProperties.getUsername()
+ "<br>" + mailProperties.getPassword();
}
打印效果
4.2. 打jar包
在工程的pom.xml中添加如下依賴
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
咱們目前的工程採用的是jar 的打包方式,因此咱們在執行package 命令後,
會產生一個jar 包。
咱們進入到這個目錄用壓縮軟件打開此jar 包,其中咱們發現了一個叫lib 的文件夾,打開lib 文件夾發現此文件夾下全是工程依賴的jar包,甚至還有tomcat。這種包含有jar 包的jar包,咱們稱之爲fatJAR( 胖jar 包)
因爲fatJAR 自己就包括tomcat , 咱們就不須要另外部署了,直接在命令行就能夠把咱們的應用啓動起來,在命令行,進入到jar 包所在的目錄,咱們能夠經過如下java –jar命令來執行此jar 包。
在控制檯會出現啓動信息,在瀏覽器訪問程序
4.3. 打war包
spring-boot 默認提供內嵌的tomcat,因此打包直接生成jar 包,用java
-jar 命令就能夠啓動。可是,有時候咱們更但願一個tomcat 來管理多個項目,
這種狀況下就須要項目是war 格式的包而不是jar 格式的包。
咱們按照如下步驟完成對工程的改造
(1)修改pom.xml
將打包方式修改成war
<packaging>war</packaging>
添加依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
spring-boot-starter-tomcat 是原來被傳遞過來的依賴,默認會打到包裏,所
以咱們再次引入此依賴,並指定依賴範圍爲provided,這樣tomcat 相關的jar
就不會打包到war 裏了.
(2)添加ServletInitializer
import org.springframework.boot.builder.SpringApplicationBuilder;
import
org.springframework.boot.context.web.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder
application) {
return application.sources(Application.class);
}
}
因爲咱們採用web3.0 規範,是沒有web.xml 的,而此類的做用與web.xml
相同。
(3)運行package 打包命令生成war 包
生成後將war 包放入tomcat,啓動tomcat,測試完成的功能是否可使用。
附錄1. Spring-boot的啓動器
(摘自Spring-boot 1.4.4官方文檔)
1. Spring Boot application starters
spring-boot-starter-thymeleaf
使用Thymeleaf視圖構建MVC Web應用程序
spring-boot-starter-ws
使用Spring Web服務。1.4不推薦使用,推薦使用spring-boot-starter-web-services
spring-boot-starter-data-couchbase
Starter for using Couchbase document-oriented database and Spring Data Couchbase
spring-boot-starter-artemis
使用Apache Artemis啓動JMS消息傳遞
spring-boot-starter-web-services
使用Spring Web服務
spring-boot-starter-mail
支持使用Java Mail和Spring Framework發送電子郵件
spring-boot-starter-data-redis
使用Redis鍵值數據存儲與Spring Data Redis和Jedis客戶端
spring-boot-starter-web
啓動器構建web,包括RESTful,使用Spring MVC的應用程序。使用Tomcat做爲默認嵌入式容器
spring-boot-starter-data-gemfire
Starter for using GemFire distributed data store and Spring Data GemFire
spring-boot-starter-activemq
使用Apache ActiveMQ啓動JMS消息傳遞
spring-boot-starter-data-elasticsearch
使用Elasticsearch搜索和分析引擎和Spring Data Elasticsearch
spring-boot-starter-integration
Starter for using Spring Integration
spring-boot-starter-test
Spring Boot應用程序用於測試包括JUnit,Hamcrest和Mockito
spring-boot-starter-hornetq
使用HornetQ啓動JMS消息傳遞。1.4已棄用,推薦使用spring-boot-starter-artemis
spring-boot-starter-jdbc
使用JDBC與Tomcat JDBC鏈接池
spring-boot-starter-mobile
使用Spring Mobile構建Web應用程序的入門
spring-boot-starter-validation
使用Java Bean校驗與Hibernate校驗器
spring-boot-starter-hateoas
使用Spring MVC和Spring HATEOAS構建基於超媒體的RESTful Web應用程序的入門
spring-boot-starter-jersey
使用JAX-RS和Jersey構建RESTful Web應用程序的入門。 spring-boot-starter-web的替代品
spring-boot-starter-data-neo4j
使用Neo4j圖數據庫和Spring Data Neo4j
spring-boot-starter-websocket
使用Spring Framework的WebSocket支持構建WebSocket應用程序
spring-boot-starter-aop
使用Spring AOP和AspectJ進行面向方面編程
spring-boot-starter-amqp
使用Spring AMQP和Rabbit MQ的入門
spring-boot-starter-data-cassandra
使用Cassandra分佈式數據庫和Spring Data Cassandra
spring-boot-starter-social-facebook
使用Spring Social Facebook
spring-boot-starter-jta-atomikos
使用Atomikos進行JTA事務
spring-boot-starter-security
使用Spring Security
spring-boot-starter-mustache
使用Mustache視圖構建MVC Web應用程序
spring-boot-starter-data-jpa
使用Spring Data JPA與Hibernate
spring-boot-starter
核心啓動器,包括自動配置支持,日誌記錄和YAML
spring-boot-starter-velocity
使用Velocity視圖構建MVC Web應用程序。1.4已棄用
spring-boot-starter-groovy-templates
使用Groovy模板視圖構建MVC Web應用程序
spring-boot-starter-freemarker
使用FreeMarker視圖構建MVC Web應用程序
spring-boot-starter-batch
使用Spring Batch
spring-boot-starter-redis
使用Redis鍵值數據存儲與Spring Data Redis和Jedis客戶端的入門。1.4已棄用,建議使用spring-boot-starter-data-redis
spring-boot-starter-social-linkedin
Stater for using Spring Social LinkedIn
spring-boot-starter-cache
支持使用Spring Framework的緩存
spring-boot-starter-data-solr
使用帶有Spring Data Solr的Apache Solr搜索平臺
spring-boot-starter-data-mongodb
使用MongoDB和Spring Data MongoDB
spring-boot-starter-jooq
使用jOOQ訪問SQL數據庫。 spring-boot-starter-data-jpa或spring-boot-starter-jdbc的替代方法
spring-boot-starter-jta-narayana
Spring Boot啓動Narayana JTA
spring-boot-starter-cloud-connectors
啓動者使用Spring Cloud鏈接器,簡化了鏈接到雲平臺中的服務,如Cloud Foundry和Heroku
spring-boot-starter-jta-bitronix
使用Bitronix進行JTA事務
spring-boot-starter-social-twitter
使用Spring Social Twitter
spring-boot-starter-data-rest
使用Spring Data REST經過REST暴露Spring數據存儲庫
2. Spring Boot production starters
spring-boot-starter-actuator
使用Spring Boot的Actuator,提供生產就緒的功能,以幫助您監視和管理您的應用程序
spring-boot-starter-remote-shell
使用CRaSH遠程shell經過SSH監視和管理您的應用程序
3. Spring Boot technical starters
spring-boot-starter-undertow
使用Undertow做爲嵌入式servlet容器。 spring-boot-starter-tomcat的替代方法
spring-boot-starter-jetty
使用Jetty做爲嵌入式servlet容器的。 spring-boot-starter-tomcat的替代方法
spring-boot-starter-logging
使用Logback進行日誌記錄。 默認日誌啓動器
spring-boot-starter-tomcat
使用Tomcat做爲嵌入式servlet容器。 spring-boot-starter-web使用的默認servlet容器
spring-boot-starter-log4j2