Mule Anypoint Studio groovy.lang.MissingPropertyException:没有这样的属性:类的 StringEscapeUtils
Posted
技术标签:
【中文标题】Mule Anypoint Studio groovy.lang.MissingPropertyException:没有这样的属性:类的 StringEscapeUtils【英文标题】:Mule Anypoint Studio groovy.lang.MissingPropertyException: No such property: StringEscapeUtils for class 【发布时间】:2020-11-05 02:53:15 【问题描述】:这适用于 Mule 4,在 4.3 EE 运行时
更新
POM 文件包含标准依赖项,感谢 Aled 的回答,也将其作为共享库包含在内:
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>$mule.maven.plugin.version</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</sharedLibrary>
<sharedLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</sharedLibrary>
<sharedLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</sharedLibrary>
<sharedLibrary>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</sharedLibrary>
<sharedLibrary>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</sharedLibrary>
<sharedLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>1.5.6</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-sockets-connector</artifactId>
<version>1.1.5</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.modules</groupId>
<artifactId>mule-secure-configuration-property-module</artifactId>
<version>1.2.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>mule-amazon-s3-connector</artifactId>
<version>5.6.0</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>mule-amazon-sns-connector</artifactId>
<version>4.4.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-spring-module</artifactId>
<version>1.3.3</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-scripting-module</artifactId>
<version>1.1.6</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>anypoint-exchange</id>
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
所需方法的测试调用:
<scripting:execute doc:name="test StringEscapeUtil" doc:id="3f3fafea-e42c-48d2-820b-69f683307b69" engine="groovy">
<scripting:code >import org.apache.commons.lang.*;
String test = "This is a test ,string \" to escape";
log.info(StringEscapeUtils.escapeCsv(test))
</scripting:code>
</scripting:execute>
实际错误:
org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : groovy.lang.MissingPropertyException: No such property: StringEscapeUtils for class: Script2
Element : test/processors/2 @ test:test/testScript.xml:47 (test StringEscapeUtil)
Element DSL : <scripting:execute doc:name="test StringEscapeUtil" doc:id="3f3fafea-e42c-48d2-820b-69f683307b69" engine="groovy">
<scripting:code>import org.apache.commons.lang.*;
String test ="This is a test ,string \"to escape";
log.info(StringEscapeUtils.escapeCsv(test))</scripting:code>
</scripting:execute>
Error type : SCRIPTING:EXECUTION
********************************************************************************
原始问题
使用 Groovy 引擎运行的脚本模块。
我已将依赖项包含在 mule maven pom 文件中:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
groovy 脚本组件确实调用了 apache commons lang3:
import org.apache.commons.lang3.*;
而调用本身就彻底失败了:
StringEscapeUtils.escapeCsv(csvText);
实际错误:
Message : groovy.lang.MissingPropertyException: No such property: StringEscapeUtils for class: Script2
【问题讨论】:
经过所有类型的测试后,我将 lang3 更改为 lang,这导致了次要问题。 Aled 的解决方案是正确的,并将其标记为正确。 【参考方案1】:由于Mule 4 classloading isolation需要在pom中将Apache Commons Lang3库标记为shared,这样脚本模块才能看到:
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>$mule.maven.plugin.version</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary> <!-- make commons-lang3 shared -->
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
【讨论】:
感谢您的洞察力。我应该补充一点,这也需要作为标准依赖项添加,否则它将无法编译并且令人沮丧地没有给出真正的解释。 话虽如此,问题依然存在。我会更新原来的问题。 正确的解决方案 - 我错误地将导入实现为 lang 而不是 lang3。当您测试某些东西并忘记将其恢复为原始值时,就会发生这种情况。以上是关于Mule Anypoint Studio groovy.lang.MissingPropertyException:没有这样的属性:类的 StringEscapeUtils的主要内容,如果未能解决你的问题,请参考以下文章
如何使用FTP连接器在Anypoint Studio中使用mule上传和下载文件?
Mule Anypoint Studio - 测试连接失败 - 进行连接测试时出现未知错误 - 自定义 API
如何在 Anypoint Studio 项目中更改 RAML 版本