Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

https://docs.microsoft.com/ko-kr/azure/developer/java/spring-framework/configure-spring-boot-initializer-java-app-with-redis-cache

https://docs.microsoft.com/ko-kr/azure/azure-cache-for-redis/cache-java-get-started

Info

Table of Contents

00. 사전조건

Info

01. Spring Boot Application 준비

01-01. Spring Boot Application 생성

Image Removed

01-02. Spring Boot Application Workspace 준비

Image Removed

01. 실행환경 청사진

Image Added

02. 개요

03. 사전조건

Info

04

...

. Create Azure Cache for Redis

...

05.

...

Spring Boot Application

...

준비

Code Blockinfo
titleGithub ProjectC:\workspace\redisdemo\src\main\resources\application.properties
linenumberstrue
# Specify the DNS URI of your Redis cache.
spring.redis.host=redis20201230.redis.cache.windows.net

# Specify the port for your Redis cache.
spring.redis.port=6379
spring.redis.ssl=true

# Specify the access key for your Redis cache.
spring.redis.password=4pgNlZPhbsla7tgi1s2qONb9YgxttV1zlecnkBJ4uxg=
Code Block
languagejava
linenumberstrue
package com.example.redisdemo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

@RestController
public class HelloController {

   @Autowired
   private StringRedisTemplate template;

   @RequestMapping("/")
   // Define the Hello World controller.
   public String hello() {

      ValueOperations<String, String> ops = this.template.opsForValue();

      // Add a Hello World string to your cache.
      String key = "greeting";
      if (!this.template.hasKey(key)) {
          ops.set(key, "Hello World!");
      }

      // Return the string from your cache.
      return ops.get(key);
   }
}

04. Execute Spring Boot Application for Azure Redis

https://github.com/Sanses/springboot-reactive-shorturl-webui

05-01. Git Clone

Code Block
C:\workspace$ git clone https://github.com/Sanses/springboot-reactive-shorturl-webui.git
Cloning into 'reactive-shorturl-webui'...
remote: Enumerating objects: 43, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 43 (delta 2), reused 39 (delta 1), pack-reused 0
Unpacking objects: 100% (43/43), done.
C:\workspace$ cd springboot-reactive-shorturl-webui

05-02. reactive-shorturl-webui Application  소개

Code Block
C:\workspace\springboot-reactive-shorturl-webui$ 
C:\workspace\springboot-reactive-shorturl-webui>mvnw
Code Block
C:\workspace\redisdemo>mvnw clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.examplesansae:redisdemoshorturl >-------------------------
[INFO] Building redisdemoshorturl 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 중략 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2123.121120 s
[INFO] Finished at: 20202021-1201-30T2202T11:0823:1904+09:00
[INFO] ------------------------------------------------------------------------

C:\workspace\redisdemo>mvnw spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.example:redisdemo >------------------------
[INFO] Building redisdemo springboot-reactive-shorturl-webui>java -jar target/shorturl-0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
~~~~~~~~~~~~~~~~ 중략 ~~~~~~~~~~~~~~~~~~~
2020-12-30 22:10:54.930  INFO 7284.jar
2021-01-02 11:24:43.050  INFO 356 --- [           main] o.s.b.wweb.embedded.tomcatnetty.TomcatWebServerNettyWebServer  : TomcatNetty initializedstarted withon port(s): 8080 (http)
20202021-1201-3002 2211:1024:5443.941192  INFO 7284356 --- [           main] ocom.apachesansae.catalina.core.StandardService shorturl.ShorturlApplication  : StartingStarted service [Tomcat]
2020-12-30 22:10:54.942  INFO 7284 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2020-12-30 22:10:55.045  INFO 7284 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-12-30 22:10:55.046  INFO 7284 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1340 ms
2020-12-30 22:10:55.526  INFO 7284 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-12-30 22:10:55.807  INFO 7284 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-12-30 22:10:55.820  INFO 7284 --- [           main] c.e.redisdemo.RedisdemoApplication       : Started RedisdemoApplication in 2.782 seconds (JVM running for 3.
388)


C:\workspace\redisdemo>curl localhost:8080
Hello World!
C:\workspace\redisdemo>

ShorturlApplication in 10.698 seconds (JVM running for 12.343)

Image Added

05-03. Code 검토

Info
titleGithub Project

https://github.com/Sanses/springboot-reactive-shorturl-webui

06. Deploy Azure WebApp

07. IntelliJ 에서 Azure Redis Caches 확인

Image Added