Integrate AppServer into your project with configuration, dependency setup, and troubleshooting guidance.
-
To get started quickly, see Getting Started.
-
To call the ApsaraVideo VOD entity class and playlist class APIs, you must submit a ticket to be added to the allowlist.
SDK integration and download
|
Download instructions |
Download URL |
|
GitHub |
Environment requirements
|
Category |
Requirement |
||||||
|
Development environment |
Spring Boot 2.6.6 or later. |
||||||
|
System version |
JDK 1.8 or later and Maven 3.x or later. |
||||||
|
Development tool |
IDE version: 5.0.3.402. Supports Windows, Mac, and Linux operating systems. |
||||||
Prerequisites
Ensure that you have obtained an AccessKey pair. For more information, see Create an AccessKey.
Configure dependencies
Add the following dependencies to the pom.xml file in your project:
The VOD SDK dependency must be version 2.16.39 or later.
<dependencies>
<!-- Spring Boot Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Alibaba Cloud Core SDK -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.3</version>
</dependency>
<!-- Alibaba Cloud VOD SDK local JAR package reference -->
<dependency>
<groupId>com.aliyun-inner</groupId>
<artifactId>aliyun-java-sdk-vod</artifactId>
<scope>system</scope>
<version>2.16.34</version>
<systemPath>${project.basedir}/src/main/resources/lib/aliyun-java-sdk-vod-2.16.34.jar</systemPath>
</dependency>
<!-- Alibaba Cloud VOD SDK -->
<!-- To deploy using Function Compute, add this dependency and comment out the local JAR package reference -->
<dependency>
<groupId>com.aliyun.inner</groupId>
<artifactId>aliyun-java-sdk-vod</artifactId>
<version>2.16.39</version>
</dependency>
<!-- Alibaba Cloud VOD Upload SDK -->
<dependency>
<groupId>com.aliyun.vod</groupId>
<artifactId>aliyun-java-vod-upload</artifactId>
<version>1.4.15</version>
</dependency>
<!-- Alibaba Cloud OSS SDK -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.17.3</version>
</dependency>
<!-- Alibaba Cloud STS SDK -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-sts</artifactId>
<version>3.0.0</version>
</dependency>
<!-- JWT authentication -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
<!-- Fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Project integration
-
Configuration file
Add the following configurations to the
application.ymlfile:server: port: 9000 aliyun: vod: # Alibaba Cloud AccessKeyId (Required) # To obtain it, visit: https://ram.console.aliyun.com/manage/ak ak: YOUR_ACCESS_KEY_ID # Alibaba Cloud AccessKeySecret (Required) sk: YOUR_ACCESS_KEY_SECRET # Region ID (Required) # Must be the same as the region where you activated ApsaraVideo VOD in the console. # Supported regions: # - China (Shanghai): cn-shanghai (Default, Recommended) # - China (Beijing): cn-beijing # - China (Shenzhen): cn-shenzhen # - Singapore: ap-southeast-1 # Support for US (West 1) (us-west-1) may be added in the future. region: cn-shanghai -
Import the core service.
Copy the following packages to your project:
com.aliyun.appserver/ ├── config/ # Configuration class ├── controller/ # Controller ├── service/ # Service interface ├── service/impl/ # Service implementation ├── dto/ # Data transfer object (DTO) ├── entity/ # Entity class ├── result/ # Unified response result └── jwt/ # JWT utility -
Configure the startup.
@SpringBootApplication @ComponentScan(basePackages = "com.aliyun.appserver") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
Verify the configuration
-
Start the project.
# Build with Maven mvn clean package # Run the project java -jar target/VodAppServer-1.0-SNAPSHOT.jar # Or, run directly with Maven mvn spring-boot:runNoteCheck the startup log and verify that it displays "VOD client initialized successfully, Region: xxx". The region must match the one configured in the
application.ymlfile. -
Verify the project.
After the project starts, test the API to verify your configuration:
# Test the playlist API curl -X POST http://localhost:9000/appServer/getPlaylists \ -H "Content-Type: application/json" \ -d '{"pageNo": "1", "pageSize": "10"}'NoteIf the API returns the VOD SDK's
GetPlaylistsResponse, the configuration is correct. For more information, see API reference.
FAQ
Project fails to start with the error Failed to initialize VOD client
Troubleshoot this issue as follows:
-
Verify that your AccessKey has the required permissions for ApsaraVideo VOD and is configured correctly.
-
Verify that the initialization region matches the region where you activated ApsaraVideo VOD in the console.
-
Verify that your network can access Alibaba Cloud services.
Cross-domain issues when calling an API
The controller is already configured with @CrossOrigin. To customize this configuration, use the following code:
@CrossOrigin(
origins = "http://your-domain.com",
methods = {RequestMethod.GET, RequestMethod.POST}
)