001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.bind.annotation; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025import org.springframework.core.annotation.AliasFor; 026import org.springframework.stereotype.Controller; 027 028/** 029 * A convenience annotation that is itself annotated with 030 * {@link Controller @Controller} and {@link ResponseBody @ResponseBody}. 031 * <p> 032 * Types that carry this annotation are treated as controllers where 033 * {@link RequestMapping @RequestMapping} methods assume 034 * {@link ResponseBody @ResponseBody} semantics by default. 035 * 036 * <p><b>NOTE:</b> {@code @RestController} is processed if an appropriate 037 * {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the 038 * {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter} 039 * pair which are the default in the MVC Java config and the MVC namespace. 040 * 041 * @author Rossen Stoyanchev 042 * @author Sam Brannen 043 * @since 4.0 044 */ 045@Target(ElementType.TYPE) 046@Retention(RetentionPolicy.RUNTIME) 047@Documented 048@Controller 049@ResponseBody 050public @interface RestController { 051 052 /** 053 * The value may indicate a suggestion for a logical component name, 054 * to be turned into a Spring bean in case of an autodetected component. 055 * @return the suggested component name, if any (or empty String otherwise) 056 * @since 4.0.1 057 */ 058 @AliasFor(annotation = Controller.class) 059 String value() default ""; 060 061}