DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Revolutionize JSON Parsing in Java With Manifold
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Grow Your Skills With Low-Code Automation Tools
  • Opportunities for Growth: Continuous Delivery and Continuous Deployment for Testers

Trending

  • Revolutionize JSON Parsing in Java With Manifold
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Grow Your Skills With Low-Code Automation Tools
  • Opportunities for Growth: Continuous Delivery and Continuous Deployment for Testers
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Hello World: Micronaut in the Cloud

Hello World: Micronaut in the Cloud

Learn how to deploy a plain Micronaut—an open-source, JVM-based framework for building microservices and serverless applications—in the cloud with Platform.sh.

Otavio Santana user avatar by
Otavio Santana
CORE ·
Jul. 02, 20 · Tutorial
Like (2)
Save
Tweet
Share
4.61K Views

Join the DZone community and get the full member experience.

Join For Free

Micronaut is an open-source, JVM-based framework for building full-stack, modular, easily testable microservice and serverless applications.

Unlike reflection-based IoC frameworks that load and cache reflection data for every single field, method, and constructor in your code, with Micronaut, your application startup time and memory consumption are not bound to the size of your codebase.

Micronaut's cloud support is built right in, including support for common discovery services, distributed tracing tools, and cloud runtimes.

The first step is to create the application itself, and Micronaut has proper documentation. You have the start code link where you can define the dependencies that you need to write your application.


As soon as you generate the application it will create an  HelloController  with the Hello world message.

Java
 




x
13


 
1
import io.micronaut.http.MediaType;
2
import io.micronaut.http.annotation.Controller;
3
import io.micronaut.http.annotation.Get;
4
import io.reactivex.Single;
5

          
6
@Controller("/")
7
public class HelloController {
8

          
9
    @Get(uri = "/", produces = MediaType.TEXT_PLAIN)
10
    public Single<String> hello() {
11
        return Single.just("Hello World! A simple Micronaut template for Platform.sh");
12
    }
13
}


The last step in the code is a start-up application.

Java
 




xxxxxxxxxx
1


 
1
import io.micronaut.runtime.Micronaut;
2

          
3
public class Application {
4

          
5
    public static void main(String[] args) {
6
        Micronaut.run(Application.class);
7
    }
8
}



To execute locally, you run the maven package application and then execute the uber-jar.

Shell
 




x


 
1
mvn clean package
2
java -jar target/micronaut-1.0-SNAPSHOT.jar



Amazing, isn't it? But how about moving this application to the cloud? Let me introduce to you Platform.sh, it is a second-generation Platform-as-a-Service built especially for continuous deployment. It allows you to host web applications on the cloud while making your development and testing workflows more productive.

As a Platform as a Service, or PaaS, Platform.sh automatically manages everything your application needs in order to run. That means you can, and should, view your infrastructure needs as part of your application, and version-control it as part of your application.

To move your application to the cloud, briefly, you need two files: 

  • One Router (.platform/routes.yaml). Platform.sh allows you to define the routes.

YAML
 




xxxxxxxxxx
1


 
1
"https://{default}/":
2
  type: upstream
3
  upstream: "app:http"
4

          
5
"https://www.{default}/":
6
  type: redirect
7
  to: "https://{default}/"


  • One or more application containers (.platform.app.yaml). You control your application and the way it will be built and deployed on Platform.sh via a single configuration file.
YAML
 




x
8


 
1
name: app
2
type: "java:8"
3
disk: 1024
4
hooks:
5
    build: mvn clean package
6
web:
7
    commands:
8
        start: java -Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError -jar target/micronaut-1.0-SNAPSHOT.jar



The application is now ready, so it’s time to move it to the cloud with Platform.sh using the following steps:

  • Create a new free trial account.
  • Sign up with a new user and password, or login using a current GitHub, Bitbucket, or Google account. If you use a third-party login, you’ll be able to set a password for your Platform.sh account later.
  • Select the region of the world where your site should live.
  • Select the blank template.

You have the option to either integrate to GitHub, GitLab, or Platform.sh will provide to you. Finally, push to the remote repository:

Shell
x
 
1
git remote add platform <platform.sh@gitrepository>
2
git commit -m "Initial project"
3
git push -u platform master


Done! We have a simple and nice Micronaut application ready to go to the cloud.

Cloud application

Opinions expressed by DZone contributors are their own.

Trending

  • Revolutionize JSON Parsing in Java With Manifold
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Grow Your Skills With Low-Code Automation Tools
  • Opportunities for Growth: Continuous Delivery and Continuous Deployment for Testers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: