001/*
002 * Copyright 2002-2019 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.reactive.config;
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.context.annotation.Import;
026
027/**
028 * Adding this annotation to an {@code @Configuration} class imports the Spring
029 * WebFlux configuration from {@link WebFluxConfigurationSupport} that enables
030 * use of annotated controllers and functional endpoints.
031 *
032 * <p>For example:
033 *
034 * <pre class="code">
035 * &#064;Configuration
036 * &#064;EnableWebFlux
037 * &#064;ComponentScan
038 * public class MyConfiguration {
039 * }
040 * </pre>
041 *
042 * <p>To customize the imported configuration, implement
043 * {@link WebFluxConfigurer} and one or more of its methods:
044 *
045 * <pre class="code">
046 * &#064;Configuration
047 * &#064;EnableWebFlux
048 * &#064;ComponentScan
049 * public class MyConfiguration implements WebFluxConfigurer {
050 *
051 *     &#064;Autowired
052 *     private ObjectMapper objectMapper;
053 *
054 *     &#064;Override
055 *     public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
056 *         configurer.defaultCodecs().jackson2JsonEncoder(
057 *             new Jackson2JsonEncoder(objectMapper)
058 *         );
059 *         configurer.defaultCodecs().jackson2JsonDecoder(
060 *             new Jackson2JsonDecoder(objectMapper)
061 *         );
062 *     }
063 *
064 *     // ...
065 * }
066 * </pre>
067 *
068 * <p>Only one {@code @Configuration} class should have the {@code @EnableWebFlux}
069 * annotation in order to import the Spring WebFlux configuration. There can
070 * however be multiple {@code @Configuration} classes that implement
071 * {@code WebFluxConfigurer} that customize the provided configuration.
072 *
073 * <p>If {@code WebFluxConfigurer} does not expose some setting that needs to be
074 * configured, consider switching to an advanced mode by removing the
075 * {@code @EnableWebFlux} annotation and extending directly from
076 * {@link WebFluxConfigurationSupport} or {@link DelegatingWebFluxConfiguration} --
077 * the latter allows detecting and delegating to one or more
078 * {@code WebFluxConfigurer} configuration classes.
079 *
080 * @author Brian Clozel
081 * @author Rossen Stoyanchev
082 * @since 5.0
083 * @see WebFluxConfigurer
084 * @see WebFluxConfigurationSupport
085 * @see DelegatingWebFluxConfiguration
086 */
087@Retention(RetentionPolicy.RUNTIME)
088@Target(ElementType.TYPE)
089@Documented
090@Import(DelegatingWebFluxConfiguration.class)
091public @interface EnableWebFlux {
092}