[英]Mule Anypoint Studio groovy.lang.MissingPropertyException: No such property: StringEscapeUtils for class
This is for Mule 4, on 4.3 EE Runtime这适用于 Mule 4,在 4.3 EE 运行时
POM File holds standard dependency, and thanks to Aled's answer also included it as a shared library: 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>
Test call of the method required:所需方法的测试调用:
<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>
Actual error:实际错误:
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
********************************************************************************
A scripting module running using Groovy Engine.使用 Groovy 引擎运行的脚本模块。
I've included the dependency in the mule maven pom file:我已将依赖项包含在 mule maven pom 文件中:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
The groovy script component does call upon the apache commons lang3: groovy 脚本组件确实调用了 apache commons lang3:
import org.apache.commons.lang3.*;
And the call itself just outright fails:调用本身就完全失败了:
StringEscapeUtils.escapeCsv(csvText);
The actual error:实际错误:
Message : groovy.lang.MissingPropertyException: No such property: StringEscapeUtils for class: Script2
Because of Mule 4 classloading isolation you need to mark the Apache Commons Lang3 library as shared in the pom, so the scripting module can see it:由于Mule 4 类加载隔离,您需要在 pom 中将 Apache Commons Lang3 库标记为共享,以便脚本模块可以看到它:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.