001/* 002 * Copyright 2012-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 * http://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.boot.autoconfigure.web.reactive; 018 019import org.springframework.boot.autoconfigure.AutoConfigureAfter; 020import org.springframework.boot.autoconfigure.AutoConfigureOrder; 021import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 022import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 023import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 024import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 025import org.springframework.context.ApplicationContext; 026import org.springframework.context.annotation.Bean; 027import org.springframework.context.annotation.Configuration; 028import org.springframework.core.Ordered; 029import org.springframework.http.server.reactive.HttpHandler; 030import org.springframework.web.reactive.DispatcherHandler; 031import org.springframework.web.server.adapter.WebHttpHandlerBuilder; 032 033/** 034 * {@link EnableAutoConfiguration Auto-configuration} for {@link HttpHandler}. 035 * 036 * @author Brian Clozel 037 * @author Stephane Nicoll 038 * @since 2.0.0 039 */ 040@Configuration 041@ConditionalOnClass({ DispatcherHandler.class, HttpHandler.class }) 042@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) 043@ConditionalOnMissingBean(HttpHandler.class) 044@AutoConfigureAfter({ WebFluxAutoConfiguration.class }) 045@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10) 046public class HttpHandlerAutoConfiguration { 047 048 @Configuration 049 public static class AnnotationConfig { 050 051 private ApplicationContext applicationContext; 052 053 public AnnotationConfig(ApplicationContext applicationContext) { 054 this.applicationContext = applicationContext; 055 } 056 057 @Bean 058 public HttpHandler httpHandler() { 059 return WebHttpHandlerBuilder.applicationContext(this.applicationContext) 060 .build(); 061 } 062 063 } 064 065}