如何使用org.omnifaces.cdi.settings.ApplicationSetting及配置问题
Troubleshooting
@ApplicationSetting Injection & Environment Configuration Let's work through your two main issues one by one to get your setup working correctly.
Fixing the Null @ApplicationSetting Injection
If your injected keyName is always null, here are the key checks to run:
- Verify OmniFaces & Dependencies: Make sure your project has a compatible OmniFaces version (this feature was introduced in OmniFaces 2.0+) and that the dependency is properly included in your build (e.g., Maven/Gradle). Double-check for missing or conflicting dependencies that might break CDI injection.
- Check Configuration File Structure & Path:
Ensure yourapplication-settings.xmlfollows the required format:
Since you're using the java-ee-kickoff-app template, confirm the project expects the config in<application-settings> <setting name="keyName">YourActualValue</setting> </application-settings>/META-INF/conf/—some setups default to/META-INF/instead. If the template uses a custom config loader, make sure it's pointing to the right directory. - Confirm CDI Activation: Your Java EE app needs a
beans.xmlfile (even an empty one) in eitherWEB-INF/orMETA-INF/to enable CDI. Without this, injection won't work at all. - Double-Check Injection Annotations: Ensure you're using the correct imports:
Also, make sure theimport javax.inject.Inject; import org.omnifaces.cdi.settings.ApplicationSetting;nameattribute in@ApplicationSettingmatches exactly with thenamein your XML (case-sensitive!). If you omit the attribute, it uses the field name—sokeyNameshould correspond to<setting name="keyName">.
Choosing & Specifying the Environment Config
The /conf/dev/, /live/, and /local-dev/ directories are for environment-specific configurations—here's how to handle them:
- Which File to Edit?
- Edit
/conf/local-dev/application-settings.xmlfor your local development environment (most common for coding/testing on your machine). - Use
/conf/dev/application-settings.xmlfor a shared development server. - Use
/conf/live/application-settings.xmlonly for production deployments.
- Edit
- How to Specify the Active Environment
The java-ee-kickoff-app typically uses a system property to determine which environment config to load. You can set this when starting your application server:- For example, add this JVM argument:
-Denvironment=local-dev - Alternatively, if you're using a container like WildFly, you can set this as an environment variable in your server configuration.
This tells the project's config loader to pull settings from the corresponding/conf/{environment}/directory instead of the default path.
- For example, add this JVM argument:
If you've checked all these and still run into issues, take a look at the project's configuration-related classes (like a ConfigLoader or similar) to see exactly how it resolves settings and environment—this will help pinpoint any mismatches in your setup.
内容的提问来源于stack exchange,提问作者jpllosa
相关产品推荐
相关产品推荐

