如何在Liberty Profile

时间:2016-11-29 16:12:38

标签: jsf websphere classloader cdi websphere-liberty

我有一些基于JSF和CDI的Web应用程序,它在Websphere ND 8.5中完美运行。然而,它在Liberty Profile 16(WebSphere Application Server 16.0.0.3/wlp-1.0.14)中不起作用。如果我尝试使用已部署的war启动Liberty Profile,则会导致

com.ibm.ws.container.service.state.StateChangeException: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001301: Annotation @javax.inject.Named(value=oam_FLOW_BUILDER_FACTORY_BEAN_NAME) is not a qualifier

当我尝试以

开头时,错误是一样的
<webApplication id="myWebApp" location="myWebApp.war" name="myWebApp">
 <classloader delegation="parentFirst"/>
</webApplication>

<webApplication id="myWebApp" location="myWebApp.war" name="myWebApp">
 <classloader delegation="parentLast"/>
</webApplication>

我正在使用这些功能:

<featureManager>
     <feature>webProfile-7.0</feature>
     <feature>localConnector-1.0</feature>
     <feature>cdi-1.2</feature>
     <feature>servlet-3.1</feature>
 </featureManager>

如果我在没有myWebApp的情况下启动Liberty Profile,然后我尝试通过Eclipse添加Web应用程序,我会

com.ibm.ws.container.service.state.StateChangeException: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions: Exception 0 : javax.enterprise.event.ObserverException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33) at java.security.AccessController.doPrivileged(Native Method) at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:40) at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:78) at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:96) at org.jboss.weld.injection.MethodInvocationStrategy$SpecialParamPlusBeanManagerStrategy.invoke(MethodInvocationStrategy.java:144) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:309) at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:124) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:287) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:265) at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:302) at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:291) at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:160) at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:154) at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:53) at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:44) at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.fire(AfterBeanDiscoveryImpl.java:62) at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:422) at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83) at com.ibm.ws.cdi.impl.CDIContainerImpl.applicationStarting(CDIContainerImpl.java:149) at com.ibm.ws.cdi.liberty.CDIRuntimeImpl.applicationStarting(CDIRuntimeImpl.java:353) at com.ibm.ws.container.service.state.internal.ApplicationStateManager.fireStarting(ApplicationStateManager.java:29) at com.ibm.ws.container.service.state.internal.StateChangeServiceImpl.fireApplicationStarting(StateChangeServiceImpl.java:51) at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.preDeployApp(DeployedAppInfoBase.java:788) at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:815) at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:66) at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:141) at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1192) at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.performAction(ApplicationStateMachineImpl.java:1038) at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:813) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.util.ServiceConfigurationError: com.sun.faces.util.cdi11.CDIUtil: Provider com.sun.faces.util.cdi11.CDIUtilImpl not a subtype at java.util.ServiceLoader.fail(ServiceLoader.java:239) at java.util.ServiceLoader.access$300(ServiceLoader.java:185) at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376) at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) at java.util.ServiceLoader$1.next(ServiceLoader.java:480) at com.sun.faces.flow.FlowCDIExtension.afterBeanDiscovery(FlowCDIExtension.java:107) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:88)

我听到有人说这是因为反射(CDI所依赖的某些功能)在Liberty Profile中不起作用,但它在WAS ND中有效。老实说,我不认为这是最后的解释。我倾向于认为这是与我失踪的类加载器相关的一些技巧。

整个库列表是:

"wsdl4j.jar" "all-themes-1.0.10.jar" "axis.jar" "check-sessionid.jar" "commons-discovery-0.2.jar" "commons-logging.jar" "javax.faces-2.2.8.jar" "javax.servlet_3.0.0.jar" "javax-inject.jar" "jaxrpc.jar" "joda-time-2.9.4.jar" "jsf-api-2.2.8.jar" "jsf-impl-2.2.8.jar" "log4j-1.2.17.jar" "log4j-boot.jar" "lombok.jar" "ojdbc6.jar" "primefaces-5.1.RC1.jar" "primefaces-5.1.RC1-sources.jar" "saaj.jar"

在WebSphere ND 8.5中,我使用以下设置成功启动了相同的Web应用程序:

1 - 特定于服务器的应用程序设置:类加载器策略

2 - 类加载器顺序:首先加载父类加载器的类

3 - WAR类加载器策略:应用程序中每个WAR文件的类加载器

4 - 共享库:

cells:hohmlweb01-aixCell01:nodes:hohmlweb01-aixNode01:servers:Sistemas_MyCompany_HML

Cell=hohmlweb01-aixCell01, Profile=Dmgr01>Shared Libraries > icefaces4.0.0 Classpath: /home/sisorb/icefaces-ace-4.0.0.jar /home/sisorb/icepush-4.0.0.jar /home/sisorb/icefaces-4.0.0.jar /home/sisorb/jfreechart-1.0.19.jar
Shared Libraries > jsf_versao_228 Classpath: /home/sisorb/jsf-api-2.2.8.jar /home/sisorb/jsf-impl-2.2.8.jar /home/sisorb/javax.faces-2.2.8.jar

如果有人至少可以告诉我如何在Liberty Profile中重现这样的WAS ND配置,那么我们将非常感激。可能我可以通过复制相同的类加载配置来解决问题。

P.S。:这个问题最初是在其他论坛上创建的,但由于我根本没有回答,我也在这里分享我的疑问(https://developer.ibm.com/answers/questions/323283/how-can-i-reproduce-same-was-nd-classloader-setup.html

*新行 我按建议评论了ConfigureListener *

    <display-name>CallCenter</display-name>
<!--<listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener> -->
    <listener>
        <listener-class>
            com.mycomp.Inicialize
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <context-param>   
        <param-name>primefaces.THEME</param-name>
        <param-value>glass-x</param-value> 
        <!-- <param-value>bluesky</param-value>  --> 
    </context-param>
    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
  • 2016年11月30日上午12:30巴西时间 我删除了“javax.faces-2.2.8.jar”“jsf-api-2.2.8.jar”“jsf-impl-2.2.8.jar” 我离开了“all-themes-1.0.10.jar”“axis.jar”“check-sessionid.jar”“commons-discovery-0.2.jar”“commons-logging.jar”“javax.servlet_3.0.0.jar” “javax-inject.jar”“jaxrpc.jar”“joda-time-2.9.4.jar”“log4j-1.2.17.jar”“log4j-boot.jar”“lombok.jar”“ojdbc6.jar”“ primefaces-5.1.RC1.jar“”primefaces-5.1.RC1-sources.jar“”saaj.jar“”wsdl4j.jar“

然后我收到了一个新错误:

Application Error
SRVE0777E: Exceção lançada pela classe de aplicativo 'javax.faces.webapp.FacesServlet.service:230'
javax.servlet.ServletException: javax.el.PropertyNotFoundException: Não alcançável no destino, identificador 'dashBean' resolvido como nulo
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:230)
at [internal classes]
Caused by: org.apache.myfaces.view.facelets.el.ContextAwarePropertyNotFoundException: javax.el.PropertyNotFoundException: Não alcançável no destino, identificador 'dashBean' resolvido como nulo
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.setValue(ContextAwareTagValueExpression.java:157)
... 1 more
Caused by: javax.el.PropertyNotFoundException: Não alcançável no destino, identificador 'dashBean' resolvido como nulo
at org.apache.el.parser.AstValue.getTarget(AstValue.java:72)
... 1 more

*在巴西时间下午2点30分新增2016/11月30日

faces-config.xml中

<?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_2.xsd"
    version="2.2">

    <application>
    <action-listener>org.primefaces.application.DialogActionListener</action-listener>
    <navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
    <view-handler>org.primefaces.application.DialogViewHandler</view-handler>
</application>

</faces-config>

Websphere Liberty Profile - server.xml

<featureManager>
    <feature>localConnector-1.0</feature>
    <feature>cdi-1.2</feature>
    <feature>jsf-2.2</feature>
</featureManager>

*在巴西时间下午4:40添加了另外两个罐子(javax.servlet_3.0.0和javax-inject)后添加2016/11/30

FFDC *创建了“com.ibm.wsspi.injectionengine.InjectionException:java.lang.NoClassDefFoundError:ServletContextEvent com.ibm.ws.webcontainer.webapp.WebApp.loadListener 672”

* FFDC是我们可以看到的更深层的日志语句

WebSphere Liberty Profile日志FFDC

Exception = com.ibm.wsspi.injectionengine.InjectionException
Source = com.ibm.ws.webcontainer.webapp.WebApp.loadListener
probeid = 672
Stack Dump = com.ibm.wsspi.injectionengine.InjectionException: java.lang.NoClassDefFoundError: ServletContextEvent
    at com.ibm.ws.webcontainer.osgi.webapp.WebApp.inject(WebApp.java:1282)
    at com.ibm.ws.webcontainer.osgi.webapp.WebApp.injectAndPostConstruct(WebApp.java:1424)
    at com.ibm.ws.webcontainer.osgi.webapp.WebApp.injectAndPostConstruct(WebApp.java:1412)
    at com.ibm.ws.webcontainer.osgi.webapp.WebApp.loadListener(WebApp.java:818)
    at com.ibm.ws.webcontainer.webapp.WebApp.loadLifecycleListeners(WebApp.java:2251)
    at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1039)
    at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6545)
    at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:466)
    at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.createRunnableHandler(DynamicVirtualHost.java:264)
    at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.createRunnableHandler(DynamicVirtualHost.java:329)
    at com.ibm.ws.http.internal.VirtualHostImpl.discriminate(VirtualHostImpl.java:251)
    at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:301)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:471)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:405)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:285)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:256)
    at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:174)
    at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:83)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:504)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:574)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:929)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1018)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: ServletContextEvent
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.jboss.weld.annotated.slim.backed.SecurityActions.getDeclaredMethods(SecurityActions.java:41)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.computeValue(BackedAnnotatedType.java:194)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.computeValue(BackedAnnotatedType.java:188)
    at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:35)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$EagerlyInitializedLazyValueHolder.<init>(BackedAnnotatedType.java:156)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.<init>(BackedAnnotatedType.java:188)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.<init>(BackedAnnotatedType.java:188)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.<init>(BackedAnnotatedType.java:63)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.of(BackedAnnotatedType.java:44)
    at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:83)
    at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:80)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3599)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2379)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2342)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2257)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4000)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4004)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4874)
    at org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java:49)
    at org.jboss.weld.util.cache.LoadingCacheUtils.getCastCacheValue(LoadingCacheUtils.java:74)
    at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:175)
    at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:194)
    at org.jboss.weld.manager.BeanManagerImpl.createAnnotatedType(BeanManagerImpl.java:1215)
    at com.ibm.ws.cdi.impl.managedobject.AbstractManagedObjectFactory.getInjectionTarget(AbstractManagedObjectFactory.java:177)
    at com.ibm.ws.cdi.impl.managedobject.AbstractManagedObjectFactory.createManagedObject(AbstractManagedObjectFactory.java:204)
    at com.ibm.ws.cdi.impl.managedobject.CDIManagedObjectFactoryImpl.createManagedObject(CDIManagedObjectFactoryImpl.java:60)
    at com.ibm.ws.webcontainer.osgi.webapp.WebApp.inject(WebApp.java:1258)
    ... 24 more
Caused by: java.lang.ClassNotFoundException: ServletContextEvent
    at com.ibm.ws.classloading.internal.AppClassLoader.findClassCommonLibraryClassLoaders(AppClassLoader.java:488)
    at com.ibm.ws.classloading.internal.AppClassLoader.findClass(AppClassLoader.java:271)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at com.ibm.ws.classloading.internal.AppClassLoader.findOrDelegateLoadClass(AppClassLoader.java:466)
    at com.ibm.ws.classloading.internal.AppClassLoader.loadClass(AppClassLoader.java:438)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 54 more

2 个答案:

答案 0 :(得分:1)

从第二个堆栈跟踪中,看起来应用程序中的一个jar正在注册CDI扩展。调用此扩展时,它会尝试加载CDI11Util服务,但不会获得预期类型的​​对象。

我怀疑这可能是jsf-impl.jar这样做的。当您使用webProfile-7.0功能(包括JSF)时,您不应该在应用程序中提供自己的JSF实现。你能尝试去掉这个罐子吗?

作为旁注,您不应该需要servlet,faces,inject或jsf API jar,因为服务器将为您的应用程序提供这些类。

作为第二个注释,Liberty中的默认类加载器设置正如您在问题中描述的那样(类加载器是父级,每个WAR都有自己的类加载器)。

答案 1 :(得分:1)

如前所述,webProfile-7.0功能包括jsf-2.2功能,该功能提供与您在应用程序中捆绑的jsf- * jars相同的EE功能(JSF 2.2)。您可以通过选择要使用的一个JSF实现来解决此问题。有两种选择:

1)将JSF实现与您的应用程序捆绑在一起:从您的服务器定义中删除webProfile-7.0功能,并仅启用您需要的(非JSF)功能。

2)从您的应用程序中删除jsf-api和jsf-impl jar。这是推荐的路由:WebSphere Liberty提供了MyFaces JSF 2.2实现。 Here is some additional information for configuring the jsf-2.2 feature