Quarkus 1.2.0.FINAL版本Qute模板无法解析问题求助
I’ve run into similar quirks with older Quarkus versions and Qute, so let’s walk through the most likely culprits and fixes for your scenario:
1. Missing Configuration for Non-HTML Template Suffixes
Quarkus 1.2.x’s Qute implementation only scans for .html templates by default. Since your template uses a .txt extension, the framework isn’t picking it up unless you explicitly tell it to include .txt files.
To fix this:
- Add the following line to your
application.propertiesfile:quarkus.qute.suffixes=html,txt - Keep your
@ResourcePathannotation using the template name without the suffix (the configured suffix list will handle matching):@Inject @ResourcePath("startTemplate") Template startTemplate;
2. Gradle Resource Packaging Issues
Sometimes custom Gradle configurations can exclude or miss the templates directory, or cached builds can prevent fresh resources from being packaged.
Check these points:
- Open your
build.gradleand confirm you haven’t excluded thetemplatesdirectory in your source sets. Your resources section should look like this (no exclusions for templates):sourceSets { main { resources { srcDirs = ["src/main/resources"] // Avoid lines like exclude 'templates/**' } } } - Run
./gradlew clean buildto clear cached artifacts—old cached resources often cause templates to go missing in the final jar. - Inspect your built jar file (look inside
BOOT-INF/classes/templates/) to verifystartTemplate.txtis present. If it’s missing, your Gradle config is the root issue.
3. Non-CDI Managed Bean
Quarkus can only inject Qute Templates into CDI-managed beans. If your LifecycleBean doesn’t have a CDI scope annotation (like @ApplicationScoped, @Singleton, or @RequestScoped), the @ResourcePath injection won’t work at all.
Fix this by adding a scope annotation to your bean:
@ApplicationScoped public class LifecycleBean { @Inject @ResourcePath("startTemplate") Template startTemplate; // Rest of your code }
4. Known Bugs in Quarkus 1.2.0.FINAL
Quarkus 1.2.0.FINAL is an old release (early 2020), and there were several Qute-related bug fixes in the subsequent 1.2.x minor releases.
Consider upgrading to the latest 1.2.x version (1.2.1.FINAL) to see if the issue resolves itself. If you’re able to make larger changes, moving to a newer Quarkus major version (like 2.x or 3.x) would give you a much more stable and feature-rich Qute implementation.
内容的提问来源于stack exchange,提问作者Snappawapa

