JBOSS 从系统属性配置上下文参数

JBOSS Configuring Context Param from System Properties

我也在使用 jboss 服务器和 primefaces。我想在登录页面使用 google 验证码。一开始没问题,验证码出现了,但我想将验证码 public 密钥和私钥存储在属性文件中。我做了这样的配置:

web.xml

   <listener>       
        <listener-class>
            com.putra.web.CaptchaConfig
        </listener-class>
    </listener>
    <context-param>
        <param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name> <!-- SECRET KEY -->
        <param-value>${PRIVATE_CAPTCHA_KEY}</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name> <!-- PUBLIC KEY -->
        <param-value>${PUBLIC_CAPTCHA_KEY}</param-value>
    </context-param>

CaptchaConfig.java

public class CaptchaConfig implements ServletContextListener {
    
    private static final Logger LOG = LoggerFactory.getLogger(CaptchaConfig.class);
    
    @Override
    public void contextDestroyed(final ServletContextEvent event) {
    }
    
    @Override
    public void contextInitialized(final ServletContextEvent event) {
        final String props = "/captcha.properties";
        final Properties propsFromFile = new Properties();
        try {
            LOG.info("### Load captcha config file ###");
            propsFromFile.load(getClass().getResourceAsStream(props));
            
        } catch (final IOException e) {
            LOG.info("### Error load captcha config file ###");
        }
        for (String prop : propsFromFile.stringPropertyNames()) {
            LOG.info("### Properties Name : {} ###", prop);
            LOG.info("### Properties Value : {} ###", propsFromFile.getProperty(prop));
            System.setProperty(prop, propsFromFile.getProperty(prop));
        }
    }
    
}

captcha.properties

PRIVATE_CAPTCHA_KEY=6Lc2QvgdAAAAAC9rcBbP2RfvVXPf2_xxxxxxxxxx
PUBLIC_CAPTCHA_KEY=6Lc2QvgdAAAAAH2Psp5-ILyWLenJJ4xxxxxxxxxx

我在 运行 项目时没有遇到任何错误,但问题是验证码没有显示。怎么了?

通过更改解决:

<spec-descriptor-property-replacement>
    false
</spec-descriptor-property-replacement>

<spec-descriptor-property-replacement>
    true
</spec-descriptor-property-replacement>

在我的 standalone-full.xml 上。谢谢!