无法在带有JSF 2.3的Wildfly 14中注入FacesContext(Mojarra,主模块) [英] FacesContext not injectable in Wildfly 14 with JSF 2.3 (Mojarra, main module)
问题描述
我有一个豆子:
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
...
@Named
@ViewScoped
public class SimpleBean implements Serializable
{
private static final long serialVersionUID = 1L;
@Inject
protected FacesContext facesContext;
...
}
根据
https:// arjan-tijms.omnifaces.org/p/jsf-23.html#1316
这应该适用于2.3 ...
this should work with 2.3 ...
部署到Wildfly 14时,结果为:
When deploying to Wildfly 14, this results in:
13:02:33,516 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 72) HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
13:02:33,563 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 72) Envers integration enabled? : true
13:02:34,344 INFO [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (ServerService Thread Pool -- 72) HHH000397: Using ASTQueryTranslatorFactory
13:02:34,531 WARN [org.jboss.weld.Bootstrap] (MSC service thread 1-1) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!
13:02:34,918 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."auth-portal.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."auth-portal.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1728)
at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1556)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type FacesContext with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject protected com.company.project.view.SimpleBean.facesContext
at com.company.project.view.SimpleBean.facesContext(SimpleBean.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:378)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:64)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:485)
13:02:34,918 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "auth-portal.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"auth-portal.war\".WeldStartService" => "Failed to start service
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type FacesContext with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject protected com.company.project.view.SimpleBean.facesContext
at com.company.project.view.SimpleBean.facesContext(SimpleBean.java:0)
"}}
我的faces-config.xml是:
My faces-config.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
...
问题:
这里出了什么问题以及如何解决这个问题?
What's wrong here and how do you solve this?
顺便说一句,这里的答案没有解决:如何使用JSF 2.3和TomEE注入FacesContext?
BTW the answer here didn't solve it: How to inject FacesContext with JSF 2.3 and TomEE?
推荐答案
根据
https://github.com/javaserverfaces/mojarra#activating-cdi-in-jsf-23
这是答案:
默认情况下,JSF 2.3将以JSF 2.2方式运行关于CDI支持。使用兼容JSF 2.3的
faces-config.xml
甚至
。换句话说,
是新的JSF 2.3注入功能和JSF工件的EL解析功能
(规格问题1316 )只有在您明确激活它后才能起作用。
换句话说,@Inject FacesContext
默认情况下不起作用。为了使JSF 2.3完全向后兼容,必须使用
。
By default, JSF 2.3 will run in JSF 2.2 modus as to CDI support. Even when you use a JSF 2.3 compatible
faces-config.xml
. In other words, the new JSF 2.3 feature of injection and EL resolving of JSF artifacts (spec issue 1316) won't work until you explicitly activate this. In other words,@Inject FacesContext
doesn't work by default. This is necessary in order for JSF 2.3 to be fully backwards compatible.
当前只有一种方法可以在JSF 2.3和
中激活CDI。因此,可以使JSF 2.3以完整的JSF 2.3方式运行。将
@FacesConfig
注释放在任意CDI托管bean上。以
为例,它是一个常规的启动/配置Bean。
There is currently only one way to activate CDI in JSF 2.3 and
herewith make JSF 2.3 to run in full JSF 2.3 modus. Put the
@FacesConfig
annotation on an arbitrary CDI managed bean. For
example, a general startup/configuration bean.
@FacesConfig
@ApplicationScoped
public class YourApplicationConfig {
// ...
}
完整示例:
import javax.enterprise.context.ApplicationScoped;
import javax.faces.annotation.FacesConfig;
@FacesConfig
@ApplicationScoped
public class Jsf23Activator {
// ...
}
您需要 @ApplicationScoped
注释,否则该注释将不起作用。之后,在我的启动中,控制台最终显示:
You need the @ApplicationScoped
annotation or it will not work. After that in my startup the console finally displays:
14:23:28,805 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 82) Initializing Mojarra 2.3.5.SP2 for context '/blah'
14:23:30,415 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 82) Monitoring file:/C:/dev/servers/wildfly-14.0.1.Final/standalone/deployments/blah.war/WEB-INF/faces-config.xml for modifications
这篇关于无法在带有JSF 2.3的Wildfly 14中注入FacesContext(Mojarra,主模块)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!