[bs-73] Tweak algorithm for detecting anonymous classes

@Bean definitions in Groovy that contain closures have the bean name in
the class name.  Ugh.  Added regex match to catch that.

[#48718891]
pull/1/merge
Dave Syer 12 years ago
parent ec351e5f7d
commit 10c333ea10

@ -1,15 +1,17 @@
package org.test package org.test
@Component @Component
@EnableIntegrationPatterns
class SpringIntegrationExample implements CommandLineRunner { class SpringIntegrationExample implements CommandLineRunner {
def builder = new IntegrationBuilder() @Bean
def flow = builder.messageFlow { MessageFlow flow(ApplicationContext context) {
transform {"Hello, $it!"} def builder = new IntegrationBuilder(context)
builder.messageFlow { transform {"Hello, $it!"} }
} }
@Override @Override
public void run(String... args) { void run(String... args) {
print flow.sendAndReceive("World") print flow().sendAndReceive("World")
} }
} }

@ -0,0 +1,20 @@
package org.test
@Grab("org.springframework.bootstrap:spring-bootstrap-service:0.0.1-SNAPSHOT")
@Grab("org.springframework.integration:spring-integration-dsl-groovy-amqp:1.0.0.M1")
@Component
@EnableIntegrationPatterns
class SpringIntegrationExample implements CommandLineRunner {
@Bean
MessageFlow flow(ApplicationContext context) {
def builder = new IntegrationBuilder(context)
builder.messageFlow { transform {"Hello, $it!"} }
}
@Override
void run(String... args) {
print flow().sendAndReceive("World")
}
}

@ -72,6 +72,8 @@ public class SpringBootstrapCompilerAutoConfiguration extends CompilerAutoConfig
"org.springframework.context.annotation.Scope", "org.springframework.context.annotation.Scope",
"org.springframework.context.annotation.Configuration", "org.springframework.context.annotation.Configuration",
"org.springframework.context.annotation.Bean", "org.springframework.context.annotation.Bean",
"org.springframework.context.ApplicationContext",
"org.springframework.context.MessageSource",
"org.springframework.core.io.ResourceLoader", "org.springframework.core.io.ResourceLoader",
"org.springframework.bootstrap.CommandLineRunner", "org.springframework.bootstrap.CommandLineRunner",
"org.springframework.bootstrap.context.annotation.EnableAutoConfiguration"); "org.springframework.bootstrap.context.annotation.EnableAutoConfiguration");

@ -16,6 +16,12 @@
package org.springframework.bootstrap.cli.compiler.autoconfigure; package org.springframework.bootstrap.cli.compiler.autoconfigure;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.bootstrap.cli.compiler.AstUtils; import org.springframework.bootstrap.cli.compiler.AstUtils;
@ -33,8 +39,8 @@ public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConf
public boolean matches(ClassNode classNode) { public boolean matches(ClassNode classNode) {
// Slightly weird detection algorithm because there is no @Enable annotation for // Slightly weird detection algorithm because there is no @Enable annotation for
// Integration // Integration
return AstUtils.hasLeastOneAnnotation(classNode, "MessageEndpoint") return AstUtils.hasLeastOneAnnotation(classNode, "MessageEndpoint",
|| classNode.getName().contains("SpringIntegration"); "EnableIntegrationPatterns");
} }
@Override @Override
@ -59,6 +65,15 @@ public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConf
"org.springframework.integration.annotation.Headers", "org.springframework.integration.annotation.Headers",
"org.springframework.integration.annotation.Payload", "org.springframework.integration.annotation.Payload",
"org.springframework.integration.annotation.Payloads", "org.springframework.integration.annotation.Payloads",
EnableIntegrationPatterns.class.getCanonicalName(),
"org.springframework.integration.dsl.groovy.MessageFlow",
"org.springframework.integration.dsl.groovy.builder.IntegrationBuilder"); "org.springframework.integration.dsl.groovy.builder.IntegrationBuilder");
} }
@Target(ElementType.TYPE)
@Documented
@Retention(RetentionPolicy.RUNTIME)
public static @interface EnableIntegrationPatterns {
}
} }

@ -163,7 +163,7 @@ class BeanDefinitionLoader {
} }
// Nested anonymous classes are not eligible for registration, nor are groovy // Nested anonymous classes are not eligible for registration, nor are groovy
// closures // closures
if (type.isAnonymousClass() || type.getName().contains("$_closure") if (type.isAnonymousClass() || type.getName().matches(".*\\$_.*closure.*")
|| type.getConstructors() == null || type.getConstructors().length == 0) { || type.getConstructors() == null || type.getConstructors().length == 0) {
return false; return false;
} }

Loading…
Cancel
Save