001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.examples.rest.springboot; 018 019import org.apache.juneau.rest.annotation.*; 020import org.apache.juneau.rest.springboot.*; 021import org.springframework.boot.autoconfigure.*; 022import org.springframework.boot.builder.*; 023import org.springframework.boot.web.servlet.*; 024import org.springframework.context.annotation.*; 025import org.springframework.stereotype.*; 026 027/** 028 * Entry point for Examples REST application when deployed as a Spring Boot application. 029 * 030 * <h5 class='section'>See Also:</h5><ul> 031 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestServerSpringbootBasics">juneau-rest-server-springboot Basics</a> 032 * </ul> 033 */ 034@SpringBootApplication 035@Controller 036public class App { 037 /** 038 * Entry point method. 039 * @param args Command-line arguments. 040 */ 041 @SuppressWarnings("resource") 042 public static void main(String[] args) { 043 try { 044 new SpringApplicationBuilder(App.class).run(args); 045 System.out.println("Initialized. App available on http://localhost:5000"); 046 } catch (Exception e) { 047 e.printStackTrace(); 048 } 049 } 050 051 /** 052 * Optionally return an injectable message provider for the {@link HelloWorldResource} class. 053 * 054 * @return The message provider for the hello-world REST bean. 055 */ 056 @Bean 057 public HelloWorldMessageProvider getHelloWorldMessageProvider() { return new HelloWorldMessageProvider("Hello Spring injection user!"); } 058 059 /** 060 * Optionally return the {@link HelloWorldResource} object as an injectable bean. 061 * 062 * @return The hello-world REST bean. 063 */ 064 @Bean 065 public HelloWorldResource getHelloWorldResource() { return new HelloWorldResource(); } 066 067 /** 068 * Our root REST bean. 069 * <p> 070 * Note that this must extend from {@link SpringRestServlet} so that child resources can be resolved as Spring 071 * beans. 072 * <p> 073 * All REST objects are attached to this bean using the {@link Rest#children()} annotation. 074 * 075 * @return The root resources REST bean. 076 */ 077 @Bean 078 public RootResources getRootResources() { return new RootResources(); } 079 080 /** 081 * @param rootResources The root REST resource servlet 082 * @return The servlet registration mapped to "/*". 083 */ 084 @Bean 085 public ServletRegistrationBean<jakarta.servlet.Servlet> getRootServlet(RootResources rootResources) { 086 return new ServletRegistrationBean<>(rootResources, "/*"); 087 } 088}