Announcing Spring Cloud Azure 4.9.0 and 5.3.0: Now Generally Available

Xiaolu Dai

We’re thrilled to announce the general availability of Spring Cloud Azure 4.9.0 and 5.3.0. These major releases bring increased compatibility with Spring Boot 2 for 4.9.0 and Spring Boot 3 for 5.3.0.

Highlighted features and improvements

Spring Cloud Azure 5.3.0

This release includes noteworthy features and enhancements such as:

  • Spring Data Cosmos and Spring Data Cosmos Starter, now compatible with Spring Boot 3.
  • Compatibility with Spring Boot 3.1.
  • Introduction of a new Spring Boot starter for Azure Event Grid.
  • Passwordless connection support for Azure Service Bus JMS.
  • Upgrades to azure-sdk-bom (version 1.2.14) and azure-resourcemanager (version 2.28.0).

Spring Cloud Azure 4.9.0

This version comes with the following additions:

  • A new Spring Boot starter for Azure Event Grid.
  • Upgrades to azure-sdk-bom (version 1.2.14) and azure-resourcemanager (version 2.28.0).

Moreover, we’ve launched the 4.9.0-beta.1 version of spring-cloud-azure-starter-openai, extending support to the Azure OpenAI service.

Let’s delve deeper into the new offerings!

What’s new?

Spring Data Cosmos

Spring Data Cosmos 5.3.0 is the first GA version compatible with Spring Boot 3. For more information, see the Spring Data Cosmos changelog.

There’s no change in how you use Spring Data Cosmos. Just add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-cosmos</artifactId>
</dependency>

Next, configure the Cosmos properties in your application.properties file:

spring.cloud.azure.cosmos.endpoint=<your-azure-cosmos-endpoint>
spring.cloud.azure.cosmos.database=<your-azure-cosmos-database>

This configuration uses the available credential on your local environment, such as Azure CLI, to connect to the Azure Cosmos DB database. To configure other types of authentication principals, see Authenticate with Entra ID.

You can define a repository in your project to save and query data as follows:

@Repository
public interface UserRepository extends CosmosRepository<User, String> {}

@Service
public class CosmosService {

    @Autowired
    private UserRepository userRepository;

    public void someMethod() {
        User testUser = new User(USER_ID, "testFirstName", "testLastName", "test address line one");
        userRepository.save(testUser);
        Optional<User> user = userRepository.findById(USER_ID);
        userRepository.delete(testUser);
    }
}

Autoconfiguration of Azure Event Grid

Azure Event Grid enables easy construction of event-based architecture applications. With the new Spring Cloud Azure starter for Event Grid, Event Grid client autoconfiguration is a breeze. For more information about Azure Event Grid, see What is Event Grid?.

To utilize this feature, add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-eventgrid</artifactId>
</dependency>

Then, configure the Event Grid properties in your application.properties file:

spring.cloud.azure.eventgrid.endpoint=https://xxx.eventgrid.azure.net/api/events
spring.cloud.azure.eventgrid.key=<your-event-grid-key>

You can also use Entra ID principals to connect to the Event Grid service. Authenticate with Entra ID offers guidance on configuring other types of authentication principals.

Here’s how you can autowire the Event Grid client:

@Autowired
EventGridPublisherClient<EventGridEvent> client;

public void someMethod(String user) {
    // ...
    // topic must be set when sending to an Event Grid Domain.
    EventGridEvent event = new EventGridEvent("A user is created",
                                              "User.Created.Object",
                                              BinaryData.fromObject(user),
                                              "0.1");
    client.sendEvent(event);
    // ...
}

Passwordless connection to Azure Service Bus JMS

Prior to the support of passwordless connections, a connection to Azure Service Bus required a connection string. However, with the new feature, you can connect to Azure Service Bus JMS using Managed Identity or any Entra ID principal. To learn more about passwordless connections, see aka.ms/passwordless-connections.

To connect to Azure Service Bus JMS with a passwordless connection, add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-servicebus-jms</artifactId>
</dependency>

Then, configure the necessary properties in application.properties:

spring.jms.servicebus.passwordless-enabled=true
spring.jms.servicebus.namespace=<your-servicebus-namespace>
spring.jms.servicebus.pricing-tier=<your-servicebus-pricing-tier> # e.g. standard
spring.cloud.azure.credential.managed-identity-enabled=true
spring.cloud.azure.credential.client-id=<your-user-assigned-managed-identity-id>

This configuration uses the user-assigned managed identity to connect to the Service Bus. To configure other types of authentication principals, see Authenticate with Entra ID.

Afterward, you can use the Spring JmsTemplate or @JmsListener in your application:

@SpringBootApplication
@EnableJms
public class ServiceBusJMSApplication implements CommandLineRunner {

    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceBusJMSApplication.class);
    private static final String QUEUE_NAME = "<QueueName>";

    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {
        SpringApplication.run(ServiceBusJMSApplication.class, args);
    }

    @Override
    public void run(String... args) {
        LOGGER.info("Sending message");
        jmsTemplate.convertAndSend(QUEUE_NAME, "Hello Word");
    }

    @JmsListener(destination = QUEUE_NAME, containerFactory = "jmsListenerContainerFactory")
    public void receiveMessage(String message) {
        LOGGER.info("Message received: {}", message);
    }

}

Azure OpenAI support

Azure OpenAI is a managed service enabling developers to deploy, tune, and generate content from OpenAI models on Azure resources.

The Spring Cloud Azure starter for Azure OpenAI allows autoconfiguration of the OpenAI client provided by the Azure SDK for Java. To use this feature, add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-openai</artifactId>
  <version>4.9.0-beta.1</version>
</dependency>

Next, configure the OpenAI properties in your application.properties file:

spring.cloud.azure.openai.endpoint=https://xxx.openai.azure.com/
spring.cloud.azure.openai.key=<your-azure-openai-key>
# or you can use the key of the public non-Azure OpenAI
# spring.cloud.azure.openai.non-azure-openai-key=<your-public-openai-key>

Then, you’re ready to autowire the OpenAI client:

@Autowired
private OpenAIClient client;

public void someMethod() {
    List<String> prompt = List.of("How many breeds of dogs are there in the world?");

    Completions completions = client.getCompletions("gpt-35-turbo", new CompletionsOptions(prompt));

    for (Choice choice : completions.getChoices()) {
        System.out.printf("Index: %d, Text: %s.%n", choice.getIndex(), choice.getText());
    }
}

One dependency BOM for all Spring Cloud Azure components

The spring-cloud-azure-dependencies BOM manages all Spring Cloud Azure components, including Cosmos and App Configuration. You can add the BOM to your project as follows:

<dependencyManagement> 
  <dependencies> 
    <dependency> 
      <groupId>com.azure.spring</groupId> 
      <artifactId>spring-cloud-azure-dependencies</artifactId> 
      <version>5.3.0</version> <!-- 4.9.0 or 4.9.0-beta.1 -->
      <type>pom</type> 
      <scope>import</scope> 
    </dependency> 
  </dependencies> 
</dependencyManagement> 

This configuration allows all Spring Cloud Azure component versions to be managed. For example:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-servicebus-jms</artifactId>
  <!-- The version can be omitted -->
</dependency>

Compatibility with Spring Boot 3.1

Spring Cloud Azure 5.3.0 is now compatible with Spring Boot 3.1. This version is compatible with both Spring Boot 3.0.x and 3.1.x. Check https://aka.ms/spring/versions for more information on versioning details.

Feedback

Your feedback and contributions are always welcome on StackOverflow or GitHub.

Resources

To learn more about Spring Cloud Azure, we invite you to visit the following links:

0 comments

Discussion is closed.

Feedback usabilla icon