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.rest.springboot; 018 019import java.util.*; 020 021import org.apache.juneau.cp.*; 022import org.apache.juneau.rest.annotation.*; 023import org.apache.juneau.rest.servlet.*; 024import org.springframework.beans.factory.annotation.*; 025import org.springframework.context.*; 026 027/** 028 * Subclass of a {@link RestServlet} that hooks into Spring Boot for using Spring Beans. 029 * 030 * <h5 class='section'>Notes:</h5><ul> 031 * <li class='note'> 032 * Users will typically extend from {@link BasicSpringRestServlet} or {@link BasicSpringRestServletGroup} 033 * instead of this class directly. 034 * </ul> 035 * 036 * <h5 class='section'>See Also:</h5><ul> 037 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestServerSpringbootBasics">juneau-rest-server-springboot Basics</a> 038 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestAnnotatedClassBasics">@Rest-Annotated Class Basics</a> 039 * </ul> 040 * 041 * @serial exclude 042 */ 043public abstract class SpringRestServlet extends RestServlet { 044 045 private static final long serialVersionUID = 1L; 046 047 @Autowired 048 private Optional<ApplicationContext> appContext; 049 050 /** 051 * Hook into Spring bean injection framework. 052 * 053 * @param parent Optional parent resource. 054 * @return A BeanStore that retrieves beans from the Spring Boot app context. 055 */ 056 @RestInject 057 public BeanStore createBeanStore(Optional<BeanStore> parent) { 058 return new SpringBeanStore(appContext, parent, this); 059 } 060}