/*
 * Copyright 2013-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.netflix.rx;

import java.util.List;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import rx.Observable;

/**
 * @author Spencer Gibb
 */
@Configuration
@ConditionalOnClass(Observable.class)
public class RxJavaAutoConfiguration {

	@Bean
	public ObservableReturnValueHandler observableReturnValueHandler() {
		return new ObservableReturnValueHandler();
	}

	@Bean
	@ConditionalOnWebApplication
	public WebMvcConfigurerAdapter observableMVCConfiguration() {
		return new WebMvcConfigurerAdapter() {
			@Override
			public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
				returnValueHandlers.add(observableReturnValueHandler());
			}
		};
	}
}

@@ -956,24 +956,108 @@
 figuration;%0A
+import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler;%0A
 import org.s
@@ -1276,16 +1276,45 @@
 uration%0A
+@ConditionalOnWebApplication%0A
 @Conditi
@@ -1383,23 +1383,167 @@
 tion %7B%0A%0A
+%09@Configuration%0A%09@ConditionalOnClass(AsyncHandlerMethodReturnValueHandler.class)%0A%09protected static class ObservableReturnValueHandlerConfig %7B%0A%09
 %09@Bean%0A
+%09
 %09public 
@@ -1602,24 +1602,25 @@
 ndler() %7B%0A%09%09
+%09
 return new O
@@ -1654,20 +1654,22 @@
 ();%0A
+%09
 %09%7D%0A%0A
+%09
 %09@Bean%0A%09
 @Con
@@ -1668,37 +1668,8 @@
 an%0A%09
-@ConditionalOnWebApplication%0A
 %09pub
@@ -1729,16 +1729,17 @@
 n() %7B%0A%09%09
+%09
 return n
@@ -1769,16 +1769,17 @@
 ter() %7B%0A
+%09
 %09%09%09@Over
@@ -1786,16 +1786,17 @@
 ride%0A%09%09%09
+%09
 public v
@@ -1887,16 +1887,17 @@
 ) %7B%0A%09%09%09%09
+%09
 returnVa
@@ -1949,18 +1949,24 @@
 ));%0A
+%09
 %09%09%09%7D%0A%09%09
+%09
 %7D;%0A
+%09%09%7D%0A
 %09%7D%0A%7D

Make RxJavaAutoConfiguration ConditionalOnClass AsyncHandlerMethodReturnValueHandler