001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.springboot;
014
015import java.util.*;
016
017import org.apache.juneau.cp.*;
018import org.apache.juneau.rest.annotation.*;
019import org.apache.juneau.rest.servlet.*;
020import org.springframework.beans.factory.annotation.*;
021import org.springframework.context.*;
022
023/**
024 * Subclass of a {@link RestServlet} that hooks into Spring Boot for using Spring Beans.
025 *
026 * <h5 class='section'>Notes:</h5><ul>
027 *    <li class='note'>
028 *       Users will typically extend from {@link BasicSpringRestServlet} or {@link BasicSpringRestServletGroup}
029 *       instead of this class directly.
030 * </ul>
031 *
032 * <h5 class='section'>See Also:</h5><ul>
033 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-server-springboot">juneau-rest-server-springboot</a>
034 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.AnnotatedClasses">@Rest-Annotated Classes</a>
035 * </ul>
036 *
037 * @serial exclude
038 */
039public abstract class SpringRestServlet extends RestServlet {
040
041   private static final long serialVersionUID = 1L;
042
043   @Autowired
044   private Optional<ApplicationContext> appContext;
045
046   /**
047    * Hook into Spring bean injection framework.
048    *
049    * @param parent Optional parent resource.
050    * @return A BeanStore that retrieves beans from the Spring Boot app context.
051    */
052   @RestInject
053   public BeanStore createBeanStore(Optional<BeanStore> parent) {
054      return new SpringBeanStore(appContext, parent, this);
055   }
056}