본문 바로가기
클라우드/Azure

[AppService] Eclipse에서 Azure App service로 SpringBoot 앱 배포

by worldcenter 2025. 1. 24.

 

시나리오

 

 

사전 준비 사항

  • Eclipse(금번 테스트에서는 2023-03 버전 사용)
  • Eclipse 내 Springboot, Gradle, Azure Toolkit for Eclipse 설치
  • Azure App Service 배포

 

 

SpringBoot 설치

  • SpringBoot는 호환성 문제로 인해 최소 Java 버전에 맞는 버전을 설치해야 합니다.
  • SpringBoot 3.0 이상부터는 최소 Java17 버전 이상이어야 합니다.
  • 금번 테스트에서는 JDK11을 사용하기에 그 아래 버전인 SpringBoot 2.6.7 설치
  • 자바 버전 Note 참조 URL
 

Home

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss. - spring-projects/spring-boot

github.com

 

1. Help > Eclipse Marketplace > Spring Tools 3 > Install 을 진행합니다.

💡 에러 발생 시 mylyn라이브러리 설치

Cannot complete the install because one or more required items could not be found. Software being installed: Spring IDE Web Flow Extension (optional) 3.9.15.202012132325-RELEASE (org.springframework.ide.eclipse.webflow.feature.feature.group 3.9.15.202012132325-RELEASE) Missing requirement: Spring IDE Configuration Graphical Editing 3.9.15.202012132325-RELEASE (org.springframework.ide.eclipse.config.graph 3.9.15.202012132325-RELEASE) requires 'osgi.bundle; org.eclipse.mylyn.commons.ui [3.7.0,4.0.0)' but it could not be found Cannot satisfy dependency: From: Spring IDE Core (required) 3.9.15.202012132325-RELEASE (org.springframework.ide.eclipse.feature.feature.group 3.9.15.202012132325-RELEASE) To: org.eclipse.equinox.p2.iu; org.springframework.ide.eclipse.config.graph [3.9.15.202012132325-RELEASE,3.9.15.202012132325-RELEASE] Cannot satisfy dependency: From: Spring IDE Web Flow Extension (optional) 3.9.15.202012132325-RELEASE (org.springframework.ide.eclipse.webflow.feature.feature.group 3.9.15.202012132325-RELEASE) To: org.eclipse.equinox.p2.iu; org.springframework.ide.eclipse.feature.feature.group 0.0.0

 

2. Help > Install New Software > Add에서 다음의 경로를 입력하여 mylyn 라이브러리를 설치합니다.

 

 

 

 

Gradle 설치

  • 기본적으로 Gradle은 Eclipse 2023-03 버전에서 설치되어 있습니다.
  • 미설치의 경우 해당 애플리케이션 환경과 동일하게 gradle 7.2 버전을 설치해야 합니다.
  • Gradle Path 설정하는 법

 

 

Azure Toolkit for Eclipse 설치

1. Eclipse Market Place 또는 Install New Software를 통해서 Azure Toolkit을 설치합니다.

이를 통해 Azure 리소스에 접근 및 즉시 배포가 가능합니다. 다음 링크에서 자세한 가이드 내용 확인 가능합니다.

 

2. Azure Toolkit이 정상적으로 설치되면 Eclipse 상단에 Tools > Azure > Sign In을 통해 Azure에 로그인합니다.

 

 

3. Azure 로그인에 성공하면 Eclipse에서 다음과 같이 Azure 인프라 내역을 확인할 수 있습니다.

 

 

Spring Music App Git Clone

금번 테스트에서 사용할 소스코드를 다음 Repository에서 Clone해야 합니다.

 

1. Eclipse Window > Perspective > Open Perspective > Other > Git 선택 후 ‘Clone a Git repository’를 선택합니다.

 

2. Clone URI > URI에 Github 경로 삽입 > Next를 선택합니다.

 

3. Git Clone한 소스코드를 저장할 디렉터리를 지정합니다.

 

4. Git Clone한 소스코드를 Eclipse Project로 import하기 위해서는 Git Repo 선택 후 우클릭하여 ‘Import Projects’ 선택합니다.

 

5. Import Source 경로를 지정하여 Finish를 선택합니다.

 

 

Gradle Build & Deploy

1. Clone한 프로젝트는 아직 Eclipse에서 Gradle 프로젝트로 인식이 안된 상태이기에 이를 인식할 수 있도록 프로젝트 우클릭 > Configure > Add Gradle Nature를 선택하여 Eclipse Gradle Task로 인식할 수 있도록 합니다.

 

2. manifest.ymlbuild.gradle에서 Java 버전을 11로 추가 및 수정합니다.

# manifest.yml
---
applications:
- name: spring-music
  memory: 1G
  random-route: true
  path: build/libs/spring-music-1.0.jar
  env:
    JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
    SPRING_PROFILES_ACTIVE: http2
    JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }'
# build.gradle
plugins {
    id 'org.springframework.boot' version '2.6.7'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'eclipse-wtp'
    id 'idea'
}

repositories {
    mavenCentral()
}

ext {
    javaCfEnvVersion = '2.4.0'
}

dependencies {
    // Spring Boot
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"
    implementation "org.springframework.boot:spring-boot-starter-data-mongodb"
    implementation "org.springframework.boot:spring-boot-starter-data-redis"
    implementation "org.springframework.boot:spring-boot-starter-validation"

    // Java Env
    implementation "io.pivotal.cfenv:java-cfenv-boot:${javaCfEnvVersion}"

    // JPA Persistence
    runtimeOnly "org.apache.commons:commons-pool2"
    runtimeOnly "com.h2database:h2"
    runtimeOnly "mysql:mysql-connector-java"
    runtimeOnly "org.postgresql:postgresql"
    runtimeOnly "com.microsoft.sqlserver:mssql-jdbc"

    // uncomment to use Lettuce instead of Jedis for Redis connections
    // runtime "io.lettuce:lettuce-core"

    // Webjars
    implementation "org.webjars:bootstrap:3.1.1"
    implementation "org.webjars:angularjs:1.2.16"
    implementation "org.webjars:angular-ui:0.4.0-2"
    implementation "org.webjars:angular-ui-bootstrap:0.10.0-1"
    implementation "org.webjars:jquery:2.1.0-2"

    // Oracle - uncomment one of the following after placing driver in ./libs
    // compile files('libs/ojdbc8.jar')
    // compile files('libs/ojdbc7.jar')

    // Testing
    testImplementation "junit:junit"
    testImplementation "org.springframework.boot:spring-boot-starter-test"
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_11

    if (JavaVersion.current() != project.targetCompatibility) {
        logger.warn("The build is using Java ${JavaVersion.current()} to build a Java ${project.targetCompatibility} compatible archive.")
        logger.warn("See the project README for instructions on changing the target Java version.")
    }
}

jar {
    enabled = false
}

 

3. Azure Webapp에서 해당 앱을 Build 및 Deploy 하기 위해서는 build.gradle 파일에서 Azure에 대한 정보를 추가해야 합니다.

# build.gradle
plugins {
    id 'org.springframework.boot' version '2.6.7'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'eclipse-wtp'
    id 'idea'
    # Azure Webapp Gradle Plugin 설치
    id 'com.microsoft.azure.azurewebapp' version '1.2.0'
}

repositories {
    mavenCentral()
}

ext {
    javaCfEnvVersion = '2.4.0'
}

dependencies {
    // Spring Boot
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"
    implementation "org.springframework.boot:spring-boot-starter-data-mongodb"
    implementation "org.springframework.boot:spring-boot-starter-data-redis"
    implementation "org.springframework.boot:spring-boot-starter-validation"

    // Java CfEnv
    implementation "io.pivotal.cfenv:java-cfenv-boot:${javaCfEnvVersion}"

    // JPA Persistence
    runtimeOnly "org.apache.commons:commons-pool2"
    runtimeOnly "com.h2database:h2"
    runtimeOnly "mysql:mysql-connector-java"
    runtimeOnly "org.postgresql:postgresql"
    runtimeOnly "com.microsoft.sqlserver:mssql-jdbc"

    // uncomment to use Lettuce instead of Jedis for Redis connections
    // runtime "io.lettuce:lettuce-core"

    // Webjars
    implementation "org.webjars:bootstrap:3.1.1"
    implementation "org.webjars:angularjs:1.2.16"
    implementation "org.webjars:angular-ui:0.4.0-2"
    implementation "org.webjars:angular-ui-bootstrap:0.10.0-1"
    implementation "org.webjars:jquery:2.1.0-2"

    // Oracle - uncomment one of the following after placing driver in ./libs
    // compile files('libs/ojdbc8.jar')
    // compile files('libs/ojdbc7.jar')

    // Testing
    testImplementation "junit:junit"
    testImplementation "org.springframework.boot:spring-boot-starter-test"
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_11

    if (JavaVersion.current() != project.targetCompatibility) {
        logger.warn("The build is using Java ${JavaVersion.current()} to build a Java ${project.targetCompatibility} compatible archive.")
        logger.warn("See the project README for instructions on changing the target Java version.")
    }
}

jar {
    enabled = false
}

# Azure에서 아래 webapp 정보와 동일한 인프라가 없는 경우 자동으로 Create
azurewebapp {
    subscription = '<Subscription ID>'
    resourceGroup = '<ResourceGroupName>'
    appName = '<AzureAppServiceName>'
    pricingTier = 'P1v3'
    region = 'koreacentral'
    runtime {
      os = 'Linux'
      webContainer = 'Java SE' 
      javaVersion = 'Java 11'
    }
}
# 만약 azurewebapp 배포 시 Oauth 방식이 아닌 Service Principal 방식으로 접속이 필요할 경우 다음과 같이 코드 변경
azurewebapp {
    subscription = '<Subscription ID>'
    resourceGroup = 'awesome-test-rg'
    appName = 'awesome-demo-music'
    pricingTier = 'P1v3'
    region = 'koreacentral'
    runtime {
      os = 'Linux'
      webContainer = 'Java SE' 
      javaVersion = 'Java 11'
    }
    deploymentSlot {
      name = 'eclipse'
    }
    auth {
      type = 'service_principal'
      client = '<ClientId>'
      tenant = '<TenantId>'
      key = '<Password>'
      environment = 'AZURE'
    }
}

 

4. 코드 수정이 완료되면 gradle build를 진행하는데 이 때 아래 명령을 사용합니다.

gradle azureWebAppDeploy

 

5. 정상적으로 앱이 Webapp에 배포되었는지 확인하기 위해서 아래 도메인으로 접속합니다.