Microservices combine all the functionality of the core, server, and client APIs to provide truly powerful and easy-to-use REST interfaces with minimal overhead.

Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-microservice-server</artifactId> <version>7.1.0</version> </dependency>

Java Library


OSGi Module


The Microservice API combines all the features above with a built-in Jetty server to produce a lightweight REST service packaged as three simple files:

The microservice API was originally designed for and particularly suited for use in Docker containers.

REST microservices can also be started programmatically in existing code:

RestMicroservice myRestService = new RestMicroservice() .setConfig("microservice.cfg", false) .setJettyXml("my-jetty.xml"); myRestService.start(); URI uri = myRestService.getURI();

The provided microservice.cfg template file gives you a starting point for defining your microservice:

#================================================================================ # Basic configuration file for SaaS microservices # Subprojects can use this as a starting point. #================================================================================ #================================================================================ # REST settings #================================================================================ [REST] # The location of the jetty.xml file to use for configuring Jetty. jettyXml = jetty.xml # Stylesheet to use for HTML views. # The default options are: # - styles/juneau.css # - styles/devops.css # Other stylesheets can be referenced relative to the servlet package or working # directory. stylesheet = styles/devops.css # What to do when the config file is saved. # Possible values: # NOTHING - Don't do anything. # RESTART_SERVER - Restart the Jetty server. # RESTART_SERVICE - Shutdown and exit with code '3'. saveConfigAction = RESTART_SERVER #================================================================================ # Logger settings # See FileHandler Java class for details. #================================================================================ [Logging] # The directory where to create the log file. # Default is "." logDir = logs # The name of the log file to create for the main logger. # The logDir and logFile make up the pattern that's passed to the FileHandler # constructor. # If value is not specified, then logging to a file will not be set up. logFile = microservice.%g.log # Whether to append to the existing log file or create a new one. # Default is false. append = # The SimpleDateFormat format to use for dates. # Default is "yyyy.MM.dd hh:mm:ss". dateFormat = # The log message format. # The value can contain any of the following variables: # {date} - The date, formatted per dateFormat. # {class} - The class name. # {method} - The method name. # {logger} - The logger name. # {level} - The log level name. # {msg} - The log message. # {threadid} - The thread ID. # {exception} - The localized exception message. # Default is "[{date} {level}] {msg}%n". format = # The maximum log file size. # Suffixes available for numbers. # See ConfigFile.getInt(String,int) for details. # Default is 1M. limit = 10M # Max number of log files. # Default is 1. count = 5 # Default log levels. # Keys are logger names. # Values are serialized Level POJOs. levels = { org.apache.juneau:'INFO' } # Only print unique stack traces once and then refer to them by a simple 8 character hash identifier. # Useful for preventing log files from filling up with duplicate stack traces. # Default is false. useStackTraceHashes = true # The default level for the console logger. # Default is WARNING. consoleLevel = #================================================================================ # System properties #-------------------------------------------------------------------------------- # These are arbitrary system properties that are set during startup. #================================================================================ [SystemProperties] # Configure Jetty for StdErrLog Logging org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog # Jetty logging level org.eclipse.jetty.LEVEL = WARN

This external config file is meant to be used for all of your resource configurations. APIs are provided in the REST Server APIs for easily accessing these values programmatically, or by using "$C{...}" variables in your @RestResource and @RestMethod annotations.

Various predefined reusable REST resource classes are provided for accessing log files, viewing and editing the config file, etc... These allow you to quickly put together sophisticated REST microservices.

Archive File


The juneau-microservice-template module is a bare-bones microservice project that can be used as a starting point for creating your own microservice.

The template project ships as a zipped Eclipse project that can be quickly imported into your workspace as an Eclipse project called "my-microservice".

Once loaded, you should see the following project structure:

The microservice can be started from the my-microservice.launch file. It will start up the microservice on port 10000 which you can then view through a browser: