You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用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 your application-settings.xml follows the required format:
    <application-settings>
        <setting name="keyName">YourActualValue</setting>
    </application-settings>
    
    Since you're using the java-ee-kickoff-app template, confirm the project expects the config in /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.xml file (even an empty one) in either WEB-INF/ or META-INF/ to enable CDI. Without this, injection won't work at all.
  • Double-Check Injection Annotations: Ensure you're using the correct imports:
    import javax.inject.Inject;
    import org.omnifaces.cdi.settings.ApplicationSetting;
    
    Also, make sure the name attribute in @ApplicationSetting matches exactly with the name in your XML (case-sensitive!). If you omit the attribute, it uses the field name—so keyName should 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.xml for your local development environment (most common for coding/testing on your machine).
    • Use /conf/dev/application-settings.xml for a shared development server.
    • Use /conf/live/application-settings.xml only for production deployments.
  • 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.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:07:18