# 在 Spring Boot 的 Web Application 使用 Redis 為 session storage ###### tags: `Spring` `Redis` `Session storage` ## Windows 版的 Redis server 到這裡[下載](https://github.com/microsoftarchive/redis/releases)免費的。 ## Windows 版的 Redis clients (GUI) * https://github.com/uglide/RedisDesktopManager/releases/download/0.8.8/redis-desktop-manager-0.8.8.384.exe * https://rdbtools.com/docs/install/windows/ ## MacOS 安裝與執行 Redis Server ### 需先安裝 [Homebrew](https://brew.sh/) 套件 {%gist pkmogy/cd6c7f91f906b5d29a296203d137b266%} ## /pom.xml ``` <!-- Redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- Spring Boot Cache --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <!-- Spring Session --> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> </dependency> ``` ## /src/main/resources/application.properties ``` # 詳細請參考 https://xxxxxxxx spring.cache.type=redis spring.redis.host=127.0.0.1 spring.redis.port=6379 ``` ## /src/main/java/{package}/Application.java ``` @EnableRedisHttpSession //加入 Redis 的 Annotation @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` [前往 Spring Security](https://hackmd.io/@LeeLo/HJvoNobgL) [前往 Spring Security Acl](https://hackmd.io/@LeeLo/HJD8s_NUH) [前往 Spring Security防止暴力破解身份驗證](https://hackmd.io/@LeeLo/HJyI3yEWL) [前往 Internationalization](https://hackmd.io/@LeeLo/By-z7tSZL)