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.SpringBootApplication; 022import org.springframework.boot.builder.*; 023import org.springframework.boot.web.servlet.*; 024import org.springframework.context.annotation.*; 025import org.springframework.stereotype.Controller; 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 //----------------------------------------------------------------------------------------------------------------- 039 // Entry point 040 //----------------------------------------------------------------------------------------------------------------- 041 042 /** 043 * Entry point method. 044 * @param args Command-line arguments. 045 */ 046 @SuppressWarnings("resource") 047 public static void main(String[] args) { 048 try { 049 new SpringApplicationBuilder(App.class).run(args); 050 System.out.println("Initialized. App available on http://localhost:5000"); 051 } catch (Exception e) { 052 e.printStackTrace(); 053 } 054 } 055 056 //----------------------------------------------------------------------------------------------------------------- 057 // Beans 058 //----------------------------------------------------------------------------------------------------------------- 059 060 /** 061 * Our root REST bean. 062 * <p> 063 * Note that this must extend from {@link SpringRestServlet} so that child resources can be resolved as Spring 064 * beans. 065 * <p> 066 * All REST objects are attached to this bean using the {@link Rest#children()} annotation. 067 * 068 * @return The root resources REST bean. 069 */ 070 @Bean 071 public RootResources getRootResources() { 072 return new RootResources(); 073 } 074 075 /** 076 * Optionally return the {@link HelloWorldResource} object as an injectable bean. 077 * 078 * @return The hello-world REST bean. 079 */ 080 @Bean 081 public HelloWorldResource getHelloWorldResource() { 082 return new HelloWorldResource(); 083 } 084 085 /** 086 * Optionally return an injectable message provider for the {@link HelloWorldResource} class. 087 * 088 * @return The message provider for the hello-world REST bean. 089 */ 090 @Bean 091 public HelloWorldMessageProvider getHelloWorldMessageProvider() { 092 return new HelloWorldMessageProvider("Hello Spring injection user!"); 093 } 094 095 /** 096 * @param rootResources The root REST resource servlet 097 * @return The servlet registration mapped to "/*". 098 */ 099 @Bean 100 public ServletRegistrationBean<jakarta.servlet.Servlet> getRootServlet(RootResources rootResources) { 101 return new ServletRegistrationBean<>(rootResources, "/*"); 102 } 103}