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

Consider allowing to exclude some beans from AOT processed applications #29484

Open
philwebb opened this issue Nov 14, 2022 · 8 comments
Open
Assignees
Labels
status: pending-design-work Needs design work before any code can be developed theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@philwebb
Copy link
Member

philwebb commented Nov 14, 2022

See spring-projects/spring-boot#32262 for background.

Currently we have a number of areas where we want to exclude beans from being used in AOT processed applications. There are a number of ways we currently do this.

  • If a bean implements BeanRegistrationAotProcessor then the isBeanExcludedFromAotProcessing result is considered.
  • If we want to filter a bean, we can use BeanRegistrationExcludeFilter in META-INF/spring/aot.factories.
  • For most other situations we use an if with AotDetector.useGeneratedArtifacts() in the actual code.

It would be nice if we could review these existing usages and see if we can find a common way to perform exclusions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 14, 2022
@sdeleuze sdeleuze added the theme: aot An issue related to Ahead-of-time processing label Nov 14, 2022
@snicoll snicoll added this to the Triage Queue milestone Nov 15, 2022
@wilkinsona
Copy link
Member

spring-projects/spring-boot#33374 is another example of beans that aren't needed after AOT processing.

@sdeleuze
Copy link
Contributor

I tentatively schedule this issue for Spring Framework 6.1.0-M1 along to #29555 as they are related and it is important to move forward on this topic.

@sdeleuze sdeleuze added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 17, 2023
@sdeleuze sdeleuze modified the milestones: Triage Queue, 6.1.0-M1 Jan 17, 2023
@dsyer
Copy link
Member

dsyer commented Feb 1, 2023

Can this be implemented in a way that doesn't require me to use an annotation? I might want to manage bean definitions for classes that I didn't write or have no control over the annotations on. E.g. register bean definitions with a well-known attribute that says "I have a supplier already, you don't need to generate any code for me". I can already do this kind of manually, and it works in my use case, by registering a BeanRegistrationExcludeFilter in aot.factories. Example:

public class ExcludeFilter implements BeanRegistrationExcludeFilter {

	static final String IGNORE_ME = "ignore.me";

	@Override
	public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
		if (registeredBean.getMergedBeanDefinition().hasAttribute(IGNORE_ME)) {
			return true;
		}
		return false;
	}

}

@sdeleuze sdeleuze added the status: pending-design-work Needs design work before any code can be developed label Feb 2, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented Feb 2, 2023

I also would like to avoid making annotation mandatory to manage this kind of concept, just not sure yet what we should use. See also use case in #29555 where annotation may not be ideal. I will discuss with @jhoeller the related design we should use.

@sdeleuze sdeleuze changed the title Consider adding annotation support for excluding beans from AOT processed applications Consider allowing to exclude some beans from AOT processed applications Feb 2, 2023
@sdeleuze sdeleuze modified the milestones: 6.1.0-M1, 6.1.0-M2 Jun 6, 2023
@sdeleuze sdeleuze modified the milestones: 6.1.0-M2, 6.1.x Jul 4, 2023
@snicoll snicoll self-assigned this Jul 10, 2023
@snicoll snicoll modified the milestones: 6.1.x, 6.x Backlog Oct 12, 2023
snicoll added a commit to snicoll/spring-framework that referenced this issue Dec 8, 2023
This commit annotates every generated class with `@Generated` so that
build tools can recognize and ignore those types if necessary.

Closes spring-projectsgh-29484
@snicoll snicoll removed the status: pending-design-work Needs design work before any code can be developed label Dec 8, 2023
@snicoll snicoll modified the milestones: 6.x Backlog, 6.1.2 Dec 8, 2023
@mmarimuthu

This comment was marked as resolved.

@dsyer

This comment was marked as resolved.

@snicoll

This comment was marked as resolved.

@mmarimuthu
Copy link

mmarimuthu commented Apr 4, 2024

@snicoll I apologize for the concern. I will try to improve.

@dsyer here is the sample

@
aot-issue.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants