Stay organized with collections
Save and categorize content based on your preferences.
Spring Cloud Google Cloud offers convenient libraries
to interface with the Vision API from a Spring application. These libraries
include
Auto-Configuration and helper classes
and Spring Boot Template classes to allow developers to get started
with the Vision API quickly.
If you're already familiar with the
Spring Framework, then
Spring Cloud Vision can
make it easier to work with the Vision API in your application and
reduce the amount of code that you need to write.
This page explains how to add Spring Cloud Vision to a Java
application. For detailed information about the module, see the
Spring Cloud Vision reference.
Dependency setup
To begin using this library, add the spring-cloud-gcp-starter-vision artifact
to your project.
Maven coordinates, using Spring Cloud Google Cloud BOM:
For more information, see the instructions for setting up a Java development
environment. You do not need to install the Google Cloud Client
Library for Java; the Spring Boot starter installs the client library
automatically.
Image analysis
After configuring the Spring Cloud Google Cloud Vision dependencies on your
classpath, you can immediately begin processing your images by getting
an instance of CloudVisionTemplate using Spring dependency injection.
The CloudVisionTemplate is a wrapper around the Vision API
Client Libraries and lets you process images easily through the
Vision API.
For more information about the CloudVisionTemplate features, see
the Cloud Vision template reference page.
The following sections contain code samples for common use cases of
the CloudVisionTemplate. All code snippets come from the Spring and
Cloud Vision sample application.
Getting the classification labels for an image
The code below extracts the classification labels for an image, providing you
with general descriptions of image content.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Using Vision with Spring framework\n\n[Spring Cloud Google Cloud](https://spring.io/projects/spring-cloud-gcp) offers convenient libraries\nto interface with the Vision API from a Spring application. These libraries\ninclude\n[Auto-Configuration and helper classes](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html)\nand Spring Boot Template classes to allow developers to get started\nwith the Vision API quickly.\n\nIf you're already familiar with the\n[Spring Framework](https://spring.io/projects/spring-framework), then\nSpring Cloud Vision can\nmake it easier to work with the Vision API in your application and\nreduce the amount of code that you need to write.\n\nThis page explains how to add Spring Cloud Vision to a Java\napplication. For detailed information about the module, see the\n[Spring Cloud Vision reference](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#cloud-vision).\n\nDependency setup\n----------------\n\nTo begin using this library, add the `spring-cloud-gcp-starter-vision` artifact\nto your project.\n\nMaven coordinates, using Spring Cloud Google Cloud BOM: \n\n \u003cdependencyManagement\u003e\n \u003cdependencies\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.cloud\u003c/groupId\u003e\n \u003cartifactId\u003espring-cloud-gcp-dependencies\u003c/artifactId\u003e\n \u003cversion\u003e1.2.8.RELEASE\u003c/version\u003e\n \u003ctype\u003epom\u003c/type\u003e\n \u003cscope\u003eimport\u003c/scope\u003e\n \u003c/dependency\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n \u003cartifactId\u003espring-boot-dependencies\u003c/artifactId\u003e\n \u003cversion\u003e${spring.version}\u003c/version\u003e\n \u003ctype\u003epom\u003c/type\u003e\n \u003cscope\u003eimport\u003c/scope\u003e\n \u003c/dependency\u003e\n \u003c/dependencies\u003e\n \u003c/dependencyManagement\u003e\n\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.cloud\u003c/groupId\u003e\n \u003cartifactId\u003espring-cloud-gcp-starter-vision\u003c/artifactId\u003e\n \u003c/dependency\u003e\n\nFor more information, see the instructions for [setting up a Java development\nenvironment](/java/docs/setup). You do not need to install the Google Cloud Client\nLibrary for Java; the Spring Boot starter installs the client library\nautomatically.\n\nImage analysis\n--------------\n\nAfter configuring the Spring Cloud Google Cloud Vision dependencies on your\nclasspath, you can immediately begin processing your images by getting\nan instance of `CloudVisionTemplate` using [Spring dependency injection](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-spring-beans-and-dependency-injection.html). \n\n @Autowired private CloudVisionTemplate cloudVisionTemplate;\n\nThe `CloudVisionTemplate` is a wrapper around the Vision API\nClient Libraries and lets you process images easily through the\nVision API.\nFor more information about the `CloudVisionTemplate` features, see\nthe [Cloud Vision template reference page](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#cloud-vision).\n\nThe following sections contain code samples for common use cases of\nthe `CloudVisionTemplate`. All code snippets come from the [Spring and\nCloud Vision sample application](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/vision/spring-framework).\n\n### Getting the classification labels for an image\n\nThe code below extracts the classification labels for an image, providing you\nwith general descriptions of image content. \n\n AnnotateImageResponse response =\n this.cloudVisionTemplate.analyzeImage(\n this.resourceLoader.getResource(imageUrl), Type.LABEL_DETECTION);\n\n Map\u003cString, Float\u003e imageLabels =\n response.getLabelAnnotationsList().stream()\n .collect(\n Collectors.toMap(\n EntityAnnotation::getDescription,\n EntityAnnotation::getScore,\n (u, v) -\u003e {\n throw new IllegalStateException(String.format(\"Duplicate key %s\", u));\n },\n LinkedHashMap::new));\n\n### Extracting the Text In an Image\n\nThe code sample below describes another common operation of extracting the text\nfrom an image. \n\n String textFromImage =\n this.cloudVisionTemplate.extractTextFromImage(this.resourceLoader.getResource(imageUrl));\n return \"Text from image: \" + textFromImage;\n\nWhat's next\n-----------\n\n- [Get started with\n Spring Cloud Google Cloud](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#getting-started).\n- Learn more about [using Spring Cloud Vision in your\n applications](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#cloud-vision).\n- [File a GitHub issue](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues) to report a bug or ask a question about the module.\n- Get more information about [Spring Framework support on\n Google Cloud](/java/docs/reference/spring).\n- Try a codelab to [deploy and run an application that uses\n Spring Cloud Google Cloud](https://codelabs.developers.google.com/spring/)."]]