Skip to content

Instantly share code, notes, and snippets.

@keesun
Created January 18, 2012 14:13
Show Gist options
  • Select an option

  • Save keesun/1633185 to your computer and use it in GitHub Desktop.

Select an option

Save keesun/1633185 to your computer and use it in GitHub Desktop.
Spring 3.1's @import, @enable and ImportAware
@Configuration
@EnableHello(name = "Keesun")
public class AppConfig {
}
@Retention(value = RetentionPolicy.RUNTIME)
@Import(HelloConfig3.class)
public @interface EnableHello {
String name();
}
@Configuration
public class HelloConfig implements ImportAware{
@Bean
public Hello hello() {
Hello h = new Hello();
h.setName("Toby");
return h;
}
@Autowired Hello hello;
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
String name = (String) importMetadata.getAnnotationAttributes(EnableHello.class.getName()).get("name");
hello.setName(name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment