Rationalize the Reactor autoconfig

It didn't make sense not to do anything at all if a Reactor @Bean
was detected, so now we only back off creating the rootReactor if
one is present.
pull/1016/merge
Dave Syer 11 years ago
parent 36e0d44eb2
commit 32dff415c3

@ -35,11 +35,11 @@ import reactor.spring.context.config.EnableReactor;
*/ */
@Configuration @Configuration
@ConditionalOnClass(EnableReactor.class) @ConditionalOnClass(EnableReactor.class)
@ConditionalOnMissingBean(Reactor.class)
@AutoConfigureAfter(WebMvcAutoConfiguration.class) @AutoConfigureAfter(WebMvcAutoConfiguration.class)
public class ReactorAutoConfiguration { public class ReactorAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(Reactor.class)
public Reactor rootReactor(Environment environment) { public Reactor rootReactor(Environment environment) {
return environment.getRootReactor(); return environment.getRootReactor();
} }

@ -16,12 +16,16 @@
package org.springframework.boot.autoconfigure.reactor; package org.springframework.boot.autoconfigure.reactor;
import static org.junit.Assert.assertNotNull;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.Environment;
import reactor.core.Reactor; import reactor.core.Reactor;
import reactor.core.spec.Reactors;
import static org.junit.Assert.assertNotNull;
/** /**
* @author Dave Syer * @author Dave Syer
@ -38,4 +42,21 @@ public class ReactorAutoConfigurationTests {
this.context.close(); this.context.close();
} }
@Test
public void customReactor() {
this.context.register(TestConfiguration.class, ReactorAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(Reactor.class));
this.context.close();
}
@Configuration
protected static class TestConfiguration {
@Bean
public Reactor reactor(Environment env) {
return Reactors.reactor().env(env).dispatcher(Environment.RING_BUFFER).get();
}
}
} }

@ -31,7 +31,8 @@ public class ReactorCompilerAutoConfiguration extends CompilerAutoConfiguration
@Override @Override
public boolean matches(ClassNode classNode) { public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableReactor") || AstUtils.hasAtLeastOneFieldOrMethod(classNode, "Reactor"); return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableReactor")
|| AstUtils.hasAtLeastOneFieldOrMethod(classNode, "Reactor");
} }
@Override @Override
@ -43,15 +44,16 @@ public class ReactorCompilerAutoConfiguration extends CompilerAutoConfiguration
@Override @Override
public void applyImports(ImportCustomizer imports) { public void applyImports(ImportCustomizer imports) {
imports.addImports("reactor.core.Reactor", "reactor.event.Event", imports.addImports("reactor.core.Reactor", "reactor.core.spec.Reactors",
"reactor.function.Consumer", "reactor.function.Functions", "reactor.core.Observable", "reactor.event.Event",
"reactor.event.selector.Selectors", "reactor.function.Functions", "reactor.function.Predicates",
"reactor.function.Suppliers",
"reactor.spring.context.annotation.Consumer", "reactor.spring.context.annotation.Consumer",
"reactor.spring.context.annotation.Selector", "reactor.spring.context.annotation.Selector",
"reactor.spring.context.annotation.SelectorType", "reactor.spring.context.annotation.SelectorType",
"reactor.spring.context.annotation.ReplyTo", "reactor.spring.context.annotation.ReplyTo",
"reactor.spring.context.config.EnableReactor") "reactor.spring.context.config.EnableReactor")
.addStarImports("reactor.event.Selectors") .addStarImports("reactor.event.selector.Selectors")
.addImport("ReactorEnvironment", "reactor.core.Environment"); .addImport("ReactorEnvironment", "reactor.core.Environment");
} }

Loading…
Cancel
Save