Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Start Spring Boot with Azure Media Service

In this article, I will walk you through creating a custom application using the spring initializr, and then access the Azure Media service and finally deploy to Azure Web app.
In order to access Azure media service in a spring boot application, we can leverage azure-mediaservices-spring-boot-starter, though it is not available in Spring Initializr yet, we can still use Spring Initializr to get start. Here, I will select both of "Azure Storage" and "Web" dependencies to generate the template shown below.

Let's open the downloaded template in Eclipse, open pom.xml, remove the Azure Storage dependency and add azure-mediaservices-spring-boot-starter dependency shown below

In order to operate with Azure media service, we need the corresponding credential. Let's execute Powershell command Get-AzureRmMediaServiceKeys shown below to get the primary key:

Now, we can open application.properties file and add below properties with the primary key we get. If you would like to access the media service via service principal, please refer to Get started with the Java client SDK for Azure Media Services and sample as well.

azure.mediaservices.account-name=media-services-account-name
azure.mediaservices.account-key=media-services-account-key

Add a controller with below source code, visit localhost:8080/Assets will return all the assets belongs to this media service account. Notice that the MediaContract is the contract to interact with the back end of media service and it supports such as create, delete, list operations. For a detailed introduction to the usage, please refer to Azure-SDK-for-java.

@RestController
public class AssetsController {
	@Autowired
        private MediaContract mediaService;
	
	@RequestMapping("/Assets")
	public ListResult Assets()
		throws Exception {
           return mediaService.list(Asset.list());
	}
}

Lastly, let's follow Deploy a Spring Boot application to the cloud with Azure App Service to deploy the sample app to azure. Below is my web.config which will be placed into wwwroot folder.

Share the post

How to Start Spring Boot with Azure Media Service

×

Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription

×