我想"测试负载"我的webapp启动时的一些复合控件(xhtml)。 但是,当我尝试获取Application上下文(getApplication())时,我遇到了这个问题:
IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory
顺便说一句,当我删除对getApplication()的调用时,webapp工作正常。所以我不认为与混合面库相关的其他stackoverflow线程是我的问题。
问题/帮助:
说明:
我正在使用Eclipse(Mars)/ Tomcat(8)/ Mojarra(2.2.0)。 我的代码目前是一个带有Java bean的简单JSF页面,它最终在静态初始化块中加载缓存配置。因此,当我开始在Eclipse中调试我的一个JSF页面时,Tomcat启动,我的静态初始化程序启动并加载我所有的"插入"信息。当它试图调用" context.getApplication()"我得到" IllegalStateException无法找到工厂javax.faces.application.ApplicationFactory"的备份。异常。
我的bean类有一个静态初始值设定项,它引用我的ENUM工厂静态值。这是我的ENUM工厂的值(我在ENUM中使用了一些静态初始化技巧,但我认为问题仍然是我早期调用了getApplication()):
public enum CvcConfigEntities {
THING1(EntityType.TYPE1),
THING2(EntityType.TYPE2);
private static final class StaticBlock {
private static final String extPropertiesClassPathFmt = CvcConfig.EXT_PROPERTIES_CLASS_PATH_FMT.getValue();
private static final Logger logger = LoggerFactory.getLogger(CvcConfigEntities.class);
private static final Properties properties = CvcConfigReader.getProperties();
private static final Hashtable<EntityType, Hashtable<String, ExtensionDescriptor>> entityTypeExtensionDescriptorsByCode = new Hashtable<>();
private static final Hashtable<EntityType, List<ExtensionDescriptor>> entityTypeExtensionDescriptorsList = new Hashtable<>();
static {
readConfiguredDescriptors();
}
最后汇集到试图加载复合组件的代码:
public static UIComponent loadCompositeComponent(String taglibURI, String tagName, String id) {
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication(); // <--- here
ViewHandler viewHandler = app.getViewHandler();
String rootViewId = context.getViewRoot().getViewId();
ViewDeclarationLanguage viewDeclarationLanguage = viewHandler.getViewDeclarationLanguage(context, rootViewId);
UIComponent composite = viewDeclarationLanguage.createComponent(context, taglibURI, tagName, null);
更大的堆栈跟踪:
SEVERE: Critical error during deployment:
com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:449)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.FacesException: java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
at com.sun.faces.config.ConfigManager.getAnnotatedClasses(ConfigManager.java:507)
at com.sun.faces.config.processor.AbstractConfigProcessor.processAnnotations(AbstractConfigProcessor.java:402)
[...]
Caused by: java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1135)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:379)
at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:140)
at com.aadhoc.cvc.common.jsf.CompositeComponentLoader.loadCompositeComponent(CompositeComponentLoader.java:13)
at com.aadhoc.cvc.extensions.ExtensionLoader.loadCompositeComponent(ExtensionLoader.java:30)
at com.aadhoc.cvc.extensions.ExtensionLoader.checkExtensionDescriptor(ExtensionLoader.java:13)
at com.aadhoc.cvc.common.config.CvcConfigEntities.readDescriptor(CvcConfigEntities.java:135)
at com.aadhoc.cvc.common.config.CvcConfigEntities.readDescriptors(CvcConfigEntities.java:89)
at com.aadhoc.cvc.common.config.CvcConfigEntities.access$2(CvcConfigEntities.java:80)
at com.aadhoc.cvc.common.config.CvcConfigEntities$StaticBlock.readConfiguredDescriptors(CvcConfigEntities.java:40)