Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pseudo-meta-annotation for @ImportAutoConfiguration #16881

Open
dsyer opened this issue May 16, 2019 · 6 comments
Open

Pseudo-meta-annotation for @ImportAutoConfiguration #16881

dsyer opened this issue May 16, 2019 · 6 comments
Labels
status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement

Comments

@dsyer
Copy link
Member

dsyer commented May 16, 2019

It would be nice to be able to @ImportAutoConfiguration(Foo.class) where Foo is itself annotated with @ImportAutoConfiguration(Bar.class) and for Bar to end up in the list of autoconfigs to be sorted and applied. It's almost a meta-annotation, but actually requires (I think) some conscious link following.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 16, 2019
@philwebb
Copy link
Member

That might have some interesting knock on effects with regular auto-configuration since presumably only Foo would be in the spring.factories file but both Foo and Bar would end up being considered.

What's driving the desire for such a change?

@dsyer
Copy link
Member Author

dsyer commented May 16, 2019

I don't know about the knock on effects exactly. The @ImportAutoConfiguration annotation isn't used in the spring.factories route AFAIK, but I don't see why this idea shouldn't apply to both with no conflicts. At the end of the day you get a list of unique autoconfig class names (from somewhere) and sort them. I think a meta feature like this could be applied to that list before it is consumed/sorted independent of the source of the initial list.

The driver is experimenting with grouping autoconfig classes together in curated sets, implemented simply as classes annotated with @ImportAutoConfiguration. Previous implementations of this have relied on custom annotations that followed the meta links. But @ImportAutoConfiguration seems to say what it means to do already, and not actually deliver what I needed.

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label May 16, 2019
@dsyer
Copy link
Member Author

dsyer commented May 17, 2019

Actually, on reflection, I got this wrong. I can always use @Import(Foo.class) and that will work. The problem might be simpler. This works:

@ImportAutoConfiguration(Bar.class)
@SpringBootConfiguration(proxyBeanMethods = false)
@ComponentScan
@AutoConfigurationPackage
@Import(Foo.class)
public class MyApplication { ... }

but this doesn't

@ImportAutoConfiguration(Bar.class)
@MySpringBootApplication(Foo.class)
public class MyApplication { ... }

with

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration(proxyBeanMethods = false)
@ComponentScan
@Import({})
@AutoConfigurationPackage
public @interface MySpringBootApplication {

	@AliasFor(annotation = Import.class)
	Class<?>[] value() default {};

}

If I can understand that, it might need a tweak in Boot, or it might be something I can fix in my code.

@philwebb
Copy link
Member

It looks to me like Spring Framework doesn't currently support @Import as a meta-annotation. I think this code would need to change.

@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label May 22, 2019
@philwebb philwebb added status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 20, 2019
@philwebb
Copy link
Member

@dsyer Are you still interested in this one?

@philwebb philwebb added this to the General Backlog milestone Dec 20, 2019
@dsyer
Copy link
Member Author

dsyer commented Dec 20, 2019

Still interested yes. Not actively working on anything that needs it though, so not urgent. I would probably do more work if this feature became available somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants