我的 mule 应用程序能够使用以下 maven 依赖项运行。
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.9.40</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
</dependency>
它运行顺利,但是一旦我向其发送 POST,它就会生成"NoClassDefFoundError"
ERROR 2015-06-11 12:34:10,406 [[dynamodb-01].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : org/apache/http/util/Args (java.lang.NoClassDefFoundError). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. org.apache.http.util.Args (java.lang.ClassNotFoundException)
java.net.URLClassLoader$1:366 (null)
2. org/apache/http/util/Args (java.lang.NoClassDefFoundError)
org.apache.http.conn.scheme.Scheme:90 (null)
3. org/apache/http/util/Args (java.lang.NoClassDefFoundError). Message payload is of type: String (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassNotFoundException: org.apache.http.util.Args
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
您的错误表明您的应用程序在运行时缺少 jar httpcore.4.4.1 中的类。尝试为要导入的库提供运行时的依赖项范围。
检查以下网址 https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.1</version>
<scope>runtime</scope>
</dependency>
如果编译和运行时也需要 jar,请使用范围"提供"。
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.1</version>
<scope>provided</scope>
</dependency>
请注意,maven 中的默认范围(如果未指定任何内容)是编译,其中库中仅用于编译。