| <!-- |
| /*************************************************************************************************************************** |
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations under the License. |
| ***************************************************************************************************************************/ |
| --> |
| |
| Installing in Eclipse |
| |
| <p> |
| Follow these instructions to create a new template project in Eclipse. |
| </p> |
| <ol class='spaced-list'> |
| <li> |
| Download the <c>my-springboot-microservice-{@property juneauVersion}.zip</c> file from the downloads page |
| (located in the binaries) and import it into your workspace as an existing project: |
| <br><br> |
| <img class='bordered' src='doc-files/my-springboot-microservice.Installing.1.png' style='width:524px'> |
| <li> |
| Select the archive file and import the project: |
| <br><br> |
| <img class='bordered' src='doc-files/my-springboot-microservice.Installing.2.png' style='width:549px'> |
| <li> |
| In your workspace, you should now see the following project: |
| <br><br> |
| <img class='bordered' src='doc-files/my-springboot-microservice.Installing.3.png' style='width:400px'> |
| </ol> |
| <p> |
| The important elements in this project are: |
| </p> |
| <ul class='spaced-list'> |
| <li> |
| <l>App.java</l> - The entry point. |
| <br>This class creates and starts our microservice. |
| <br>Note that we're using the existing Spring Boot application logic for the microservice and we're retrieving |
| our root resource as a spring bean. |
| <br>Only the top-level resource needs to be annotated with {@link oaj.rest.springboot.annotation.JuneauRestRoot @JuneauRestRoot} |
| <br><br> |
| <p class='bcode w800'> |
| <ja>@SpringBootApplication</ja> |
| <ja>@Controller</ja> |
| <jk>public class</jk> App { |
| |
| <jk>public static void</jk> main(String[] args) { |
| <jk>new</jk> SpringApplicationBuilder(App.<jk>class</jk>) |
| .initializers(<jk>new</jk> JuneauRestInitializer(App.<jk>class</jk>)) |
| .run(args); |
| } |
| |
| <ja>@Bean @JuneauRestRoot</ja> |
| <jk>public</jk> RootResources getRootResources() { |
| <jk>return new</jk> RootResources(); |
| } |
| } |
| </p> |
| <li> |
| <l>RootResources.java</l> - The top-level REST resource. |
| <br>This class routes HTTP requests to child resources. |
| <br>This is identical to the Jetty example. |
| <br><br> |
| <p class='bcode w800'> |
| <ja>@Rest</ja>( |
| path=<js>"/"</js>, |
| title=<js>"My Microservice"</js>, |
| description=<js>"Top-level resources page"</js>, |
| htmldoc=<ja>@HtmlDoc</ja>( |
| widgets={ |
| ContentTypeMenuItem.<jk>class</jk>, |
| StyleMenuItem.<jk>class</jk> |
| }, |
| navlinks={ |
| <js>"options: servlet:/?method=OPTIONS"</js> |
| } |
| ), |
| children={ |
| HelloWorldResource.<jk>class</jk>, |
| ConfigResource.<jk>class</jk>, |
| LogsResource.<jk>class</jk> |
| } |
| ) |
| <jk>public class</jk> RootResources <jk>extends</jk> BasicRestServletJenaGroup { |
| <jc>// No code</jc> |
| } |
| </p> |
| <li> |
| <l>juneau.cfg</l> - The configuration file. |
| <br>Contains various useful settings. |
| <br>Can be used for your own resource configurations. |
| <br>Note that the Jetty configuration is not present. |
| <br>Also it's located in the classpath so that our microservice can be built as a single executable jar. |
| <br><br> |
| <p class='bcode w800'> |
| <cc>#======================================================================================================================= |
| # Basic configuration file for REST microservices |
| # Subprojects can use this as a starting point. |
| #=======================================================================================================================</cc> |
| |
| <cc>#======================================================================================================================= |
| # REST settings |
| #=======================================================================================================================</cc> |
| <cs>[REST]</cs> |
| |
| <cc># Comma-delimited list of key-value pairs that represent locations of static files that can be served up by your @Rest-annotated |
| # classes. These are static files that are served up by the servlet under the specified sub-paths. |
| # For example, given the following setting... |
| # staticFiles = htdocs:my-docs,styles/my-styles |
| # ...the URI "/servletPath/htdocs/javadoc.css" resolves to the path "/my-docs/javadoc.css". |
| # This path can be relative to the working directory, classpath root, or package of your resource class. |
| # Used by the BasicRestConfig interface that defines the following value: |
| # staticFiles="$C{REST/staticFiles}"</cc> |
| <ck>staticFiles</ck> = htdocs:htdocs |
| |
| <cc># Stylesheet to use for HTML views. |
| # Used by the BasicRestConfig interface that defines the following value: |
| # stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}"</cc> |
| <ck>theme</ck> = <cv>servlet:/htdocs/themes/devops.css</cv> |
| |
| <cc># Various look-and-feel settings used in the BasicRestConfig interface.</cc> |
| <ck>headerIcon</ck> = <cv>servlet:/htdocs/images/juneau.png</cv> |
| <ck>headerLink</ck> = <cv>http://juneau.apache.org</cv> |
| <ck>footerIcon</ck> = <cv>servlet:/htdocs/images/asf.png</cv> |
| <ck>footerLink</ck> = <cv>http://www.apache.org</cv> |
| <ck>favicon</ck> = <cv>$C{REST/headerIcon}</cv> |
| <ck>header</ck> = |
| <cv><a href='$U{$C{REST/headerLink}}'> |
| <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> |
| </a></cv> |
| <ck>footer</ck> = |
| <cv><a href='$U{$C{REST/footerLink}}'> |
| <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> |
| </a></cv> |
| </p> |
| </ul> |
| <p> |
| At this point, you're ready to start the microservice from your workspace. |
| </p> |