Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Investigate Adding Fallback for Beans with no Matching Generic Parameters #1097

Closed
garyrussell opened this issue Sep 28, 2021 · 2 comments
Closed
Labels
for: external-project For an external project and not something we can fix type: compatibility Native image compatibility issue

Comments

@garyrussell
Copy link
Contributor

#1078 (comment)

For example, Boot auto configures a KafkaTemplate<Object, Object> without AOT, the framework has several layers fallbacks such that KafkaTemplate<String, String> can be auto wired as a dependency.

Unfortunately, AOT does not support this "feature" so there is no match during wiring since a bean with the expected generic type parameters is required.

While this might be the correct behavior, it feels like missing functionality with AOT.

The work around in the Kafka samples was to use <Object, Object>.

Perhaps a better work around would be to inject the beans with no generics and perform an unchecked cast....

	@Bean
	public ApplicationRunner runner(KafkaTemplate templateArg,
				ConsumerFactory cfArg) {

		@SuppressWarnings("unchecked")
		KafkaTemplate<String, String> template = templateArg;
		@SuppressWarnings("unchecked")
		ConsumerFactory<String, String> cf = cfArg;
		cf.addListener(new ConsumerFactory.Listener() { });
		return args -> {
			template.send("graal", "foo");
			System.out.println("++++++Sent:foo");
			Thread.sleep(5000);
		};
	}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 28, 2021
@snicoll
Copy link
Contributor

snicoll commented Sep 29, 2021

paging @jhoeller

@sdeleuze sdeleuze added this to the Backlog milestone Sep 30, 2021
@sdeleuze sdeleuze added type: compatibility Native image compatibility issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 30, 2021
@sdeleuze sdeleuze added the for: external-project For an external project and not something we can fix label Jan 2, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 2, 2023

Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.

As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer.

Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.

@sdeleuze sdeleuze closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2023
@sdeleuze sdeleuze removed this from the Backlog milestone Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
for: external-project For an external project and not something we can fix type: compatibility Native image compatibility issue
Development

No branches or pull requests

4 participants