我正在尝试运行一个在Apache CXF中编码的Web服务。我一直收到这个错误:
Stacktrace:] with root cause
java.lang.ClassNotFoundException: org.apache.cxf.message.Message
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
我已经将cxf-core
工件添加到我的pom文件中,并且我可以看到它包含在WAR文件中。还有实际抛出异常的JAR。引发异常的代码部分是:
getBindingProvider().getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT, connectTimeout);
getBindingProvider().getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPointUrl);
getBindingProvider().getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 3720000);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Content-Type", Collections.singletonList("application/soap+xml"));
headers.put(Message.CONTENT_TRANSFER_ENCODING, Collections.singletonList("UTF-8"));
headers.put(Message.ENCODING, Collections.singletonList("UTF-8"));
getBindingProvider().getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
我做错什么了吗?
我正在用maven jar插件构建它,就像这样:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultEntries>true</addDefaultEntries>
<addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<attachClasses>true</attachClasses>
<includeEmptyDirectories>true</includeEmptyDirectories>
<outputDirectory>${project.basedir}/target/</outputDirectory>
</configuration>
</plugin>
您是如何运行它的?如果运行war文件(其中包含cxf-jar文件,其中包含Message类(,则不应引发classcastexception。除非您有冲突的依赖关系。或者类加载器出了问题。
检查是否存在冲突的罐子。在intellij中,它们被标记在屏幕的右侧。Eclipse也有类似的东西。