A Spring RESTful microservice
This sample contains a way of how to use Swagger documentation within Liberty or Tomcat (SpringBoot). It also introduces the database connection with DB2 by using the JDBC datasource and the JpaRepository.
Note: If you don't need to store any data in the database, please take a look at this "No DB Connection version". https://github.com/microservices-api/spring-rest/tree/NoDBConnection
- In the Git Repository view, expand the sample repo to see the "Working Directory" folder
- Right-click on this folder, and select Copy path to Clipboard
- Select menu File -> Import -> Maven -> Existing Maven Projects
- In the Root Directory textbox, Paste in the repository directory.
- Select Browse... button and select Finish (confirm it finds 3 pom.xml files)
- This will create 3 projects in Eclipse: swagger-sample, swagger-sample-application, and swagger-sample-wlpcfg
Note: If you did not use Eclipse/WDT to clone the git repository, follow from step 3, but navigate to the cloned repository directory rather than pasting its name in step 4.
- Right-click on swagger-sample/pom.xml
- Run As > Maven build...
- In the Goals section enter "install"
- Click Run
- Open the 'Runtime Explorer' view:
- Window -> Show View -> Other
- type
runtime
in the filter box to find the view (it's under the Server heading).
- Right-click in the view, and select New -> Runtime Environment
- Give the Runtime environment a name, e.g.
wlp-2017.1.0.0
if you're using the January 2017 version. - Either:
- Select an existing installation (perhaps what you downloaded earlier, if you followed those instructions), or
- select Install from an archive or a repository to download a new Liberty archive.
- Follow the prompts (and possibly choose additional features to install) until you Finish creating the Runtime Environment
- Right-click on the Runtime Environment created above in the 'Runtime Explorer' view, and select Edit
- Click the
Advanced Options...
link - If the
swagger-sample-wlpcfg
directory is not listed as a User Directory, we need to add it:- Click New
- Select the
swagger-sample-wlpcfg
project - Select Finish, OK, Finish
- Right-click on the
swagger-sample-wlpcfg
user directory listed under the target Runtime Environment in the Runtime Explorer view, and select New Server. - The resulting dialog should be pre-populated with the
swaggerSample
Liberty profile server. The default name for this server can vary, you might also opt to rename it from the Right-click menu in the Servers view to make it easier to identify. - Click Finish
- Select the
swagger-sample-application
project - Right-click -> Run As... -> Run On Server
- Select the appropriate server (as created above) and select Finish
- Select the
swagger-sample-application
project - Right-click -> Run As... -> Spring Boot App Note: The Tomcat server will be automatically started. "Started Application in ... seconds (JVM running for ...)" message suggests the compiled war file is deployed and started successfully on the Tomcat server.
- Access to http://localhost:8080/swagger-ui.html