DEV Community

Apurv
Apurv

Posted on • Originally published at apurvsheth.Medium on

Serverless with Spring

1. Introduction :

In this article, we have gone through the functional interface implementation feature introduced in Java8.

Now, we will learn how to leverage functional interface implementation using spring boot.

2. Tool(s)/Framework(s):

  • Any java project tool suite like Spring tool suit, eclipse, IntelliJ
  • JDK 8 or above
  • Spring boot 2.x & above

3. Prerequisites:

  • Java functional interface
  • Lambda

4. Spring Cloud Function Setup

4.1 Maven Dependencies



org.springframework.cloud

spring-cloud-starter-function-web

4.2 Writing Spring Cloud Function

Writing a spring cloud function like supplier, consumer, or function is very simple. We can define bean for each type of function & we can access this functional implementation via its method name.

For Ex:

/**

* Function implementation.

*

* @return Function

*/

@Bean

public Function welcome () {

return (userName) -> “Welcome “ + userName + “ to the functional programming”;

}

4.3 Testing

We can verify the spring cloud function written above with curl command as given below.

curl http://localhost:8080/welcome -H “Content-Type: text/plain” -d apurv

5. Key takeaways

The spring cloud function is a really powerful feature that abstracts business logic from all of transport details & infrastructure. It might be in its earlier stage but there are many benefits via which we can,

  • use all spring boot features like auto-configuration, dependency injection & many more.
  • build cloud-agnostic unified programming model, across serverless providers.
  • leverage same code & can run as a web endpoint, a stream processor, or a task.

6. Git Repo

https://github.com/shethaptech/spring-boot.git

7 . References:

https://spring.io/projects/spring-cloud-function#support

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay