gpt4 book ai didi

java - 为什么我在 CXF 中收到此错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:55:06 25 4
gpt4 key购买 nike

我想使用 CXF 在 JSF 中创建动态 Web 服务调用程序。但是当我加载这个简单的代码时,我收到错误。代码:

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://ws.strikeiron.com/IPLookup2?wsdl");

错误:

没有为此应用程序配置工厂。如果面部初始化根本不起作用,就会发生这种情况 - 确保正确包含基本面部应用程序所需的所有配置设置,并且包含所有必需的库。还要检查 Web 应用程序和容器的日志输出是否有任何异常!如果您这样做了但什么也没找到,则错误可能是由于您使用了一些特殊的 Web 容器,这些容器不支持通过 TLD 文件注册上下文监听器,并且您的 web.xml 中未设置上下文监听器。典型的配置如下所示; org.apache.myfaces.webapp.StartupServletContextListener

原因:java.lang.IllegalStateException - 没有为此应用程序配置工厂。如果面部初始化根本不起作用,就会发生这种情况 - 确保正确包含基本面部应用程序所需的所有配置设置,并且包含所有必需的库。还要检查 Web 应用程序和容器的日志输出是否有任何异常!如果您这样做了但什么也没找到,则错误可能是由于您使用了一些特殊的 Web 容器,这些容器不支持通过 TLD 文件注册上下文监听器,并且您的 web.xml 中未设置上下文监听器。典型的配置如下所示; org.apache.myfaces.webapp.StartupServletContextListener

知道如何解决这个问题吗?

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ServiceInvoker</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</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>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<managed-bean>
<description>Bean used for invoking services</description>
<managed-bean-name>invoker</managed-bean-name>
<managed-bean-class>org.cot.invoker.Invoker</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

</faces-config>

这是我在 Eclipse 控制台中得到的内容:

22.3.2010 15:00:11 org.apache.cxf.endpoint.dynamic.DynamicClientFactory 输出调试信息:创建的类:com.strikeiron.ws.GetRemainingHits、com.strikeiron.ws.GetRemainingHitsResponse、com.strikeiron.ws.LicenseInfo、com.strikeiron.ws.ObjectFactory、com.strikeiron.ws.RegisteredUser、com.strikeiron.ws.SubscriptionInfo、com.strikeiron.ws.UnregisteredUser 、 com.strikeiron.ArrayOfMethodStatusRecord、 com.strikeiron.ArrayOfSIWsStatus、 com.strikeiron.ArrayOfServiceInfoRecord、 com.strikeiron.ArrayOfString、 com.strikeiron.ArrayOfString1、 com.strikeiron.DNSInfo、 com.strikeiron.DNSLookup、 com.strikeiron.DNSLookupResponse、 com.strikeiron.GetServiceInfo、 com.strikeiron.GetServiceInfoResponse、com.strikeiron.GetStatusCodes、com.strikeiron.GetStatusCodesForMethod、com.strikeiron.GetStatusCodesForMethodResponse、com.strikeiron.GetStatusCodesResponse、com.strikeiron.MethodStatusRecord、com.strikeiron.ObjectFactory、com.strikeiron.SIWsOutputOfDNSInfo、com. Strikeiron.SIWsOutputOfMethodStatusRecord、 com.strikeiron.SIWsOutputOfSIWsResultArrayOfMethodStatusRecord、 com.strikeiron.SIWsOutputOfSIWsResultArrayOfServiceInfoRecord、 com.strikeiron.SIWsResultArrayOfMethodStatusRecord、 com.strikeiron.SIWsResultArrayOfSIWsStatus、 com.strikeiron.SIWs ResultArrayOfServiceInfoRecord、com.strikeiron.SIWsStatus、com.strikeiron.ServiceInfoRecord杰斯洛22.3.2010 15:00:13 javax.faces.webapp._ErrorPageWriterhandleThrowable严重:发生异常java.lang.IllegalStateException:没有为此应用程序配置工厂。如果面部初始化根本不起作用,就会发生这种情况 - 确保正确包含基本面部应用程序所需的所有配置设置,并且包含所有必需的库。还要检查 Web 应用程序和容器的日志输出是否有任何异常!如果您这样做了但什么也没找到,则错误可能是由于您使用了一些特殊的 Web 容器,这些容器不支持通过 TLD 文件注册上下文监听器,并且您的 web.xml 中未设置上下文监听器。典型的配置如下所示; org.apache.myfaces.webapp.StartupServletContextListener

at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:106)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:356)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:155)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

当我点击:

<h:commandLink value="Invoke me!" actionListener="#{invoker.doInvoke}"></h:commandLink>

最佳答案

为了避免使用 CXF 动态客户端和 JSF 出现“没有为此应用程序配置工厂”之类的错误,您必须执行以下操作:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://ws.strikeiron.com/IPLookup2?wsdl");
Thread.currentThread().setContextClassLoader(classLoader);

关于java - 为什么我在 CXF 中收到此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2489205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com