[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]
This commit is contained in:
Dave Syer 2013-04-26 12:02:49 +01:00
parent ec351e5f7d
commit 10c333ea10
5 changed files with 48 additions and 9 deletions

View File

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

View File

@ -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")
}
}

View File

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

View File

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

View File

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