WSO2 Integration Studio8.0.0出现JsonUtil无法解析报错如何解决
WSO2 Integration Studio 8.0.0 Mediator项目JsonUtil无法解析问题
问题描述
使用WSO2 Integration Studio 8.0.0基于WSO2 Mediator Project创建JSON payload时,IDE抛出如下错误:
JsonUtil cannot be resolved
报错截图:
当前项目pom.xml配置
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.test.in</groupId> <artifactId>Jubilant_EmailTicketing</artifactId> <version>1.0.0</version> <relativePath>..\pom.xml</relativePath> </parent> <groupId>com.jubilant.in.Jubilant_EmailTicketing-Mediator</groupId> <artifactId>Jubilant_EmailTicketing-Mediator</artifactId> <version>1.0.0</version> <packaging>bundle</packaging> <name>Jubilant_EmailTicketing-Mediator</name> <description>Jubilant_EmailTicketing-Mediator</description> <properties> <CApp.type>lib/synapse/mediator</CApp.type> </properties> <dependencies> <dependency> <groupId>org.apache.axis2.wso2</groupId> <artifactId>axis2</artifactId> <version>1.6.1.wso2v20</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20141113</version> </dependency> <!-- Requested Dependency --> <dependency> <groupId>org.apache.synapse</groupId> <artifactId>synapse-commons</artifactId> <version>3.0.1</version> </dependency> </dependencies> <repositories> <repository> <releases> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </releases> <id>wso2-nexus</id> <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </releases> <id>wso2-nexus</id> <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url> </pluginRepository> </pluginRepositories> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.3.4</version> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>Jubilant_EmailTicketing-Mediator</Bundle-SymbolicName> <Bundle-Name>Jubilant_EmailTicketing-Mediator</Bundle-Name> <Export-Package>com.jubilant.in</Export-Package> <DynamicImport-Package>*</DynamicImport-Package> </instructions> </configuration> </plugin> <plugin> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <buildcommands> <buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand> </buildcommands> <projectnatures> <projectnature>org.wso2.developerstudio.eclipse.artifact.mediator.project.nature</projectnature> <projectnature>org.eclipse.jdt.core.javanature</projectnature> </projectnatures> </configuration> </plugin> </plugins> </build> </project>
已尝试操作
参考相关文档添加了上述依赖,仍未解决报错,使用的导入语句如下:
import org.apache.synapse.commons.json.JsonUtil;
解决方案
该报错的核心原因是你引入的是Apache官方原生的synapse-commons依赖,org.apache.synapse.commons.json.JsonUtil是WSO2在自研分支中新增的类,不存在于原生Apache Synapse版本中。
按以下步骤修改即可解决:
- 替换pom.xml中的synapse-commons依赖,删除原有原生版本依赖,添加WSO2维护的适配版本:
<dependency> <groupId>org.apache.synapse.wso2</groupId> <artifactId>synapse-commons</artifactId> <version>2.1.7-wso2v225</version> <scope>provided</scope> </dependency>
注:添加
<scope>provided</scope>是因为该依赖在WSO2服务器运行环境中已内置,无需打包进你自己的中介器包,可避免依赖冲突。
- 强制更新Maven依赖:右键项目 → 选择
Maven→ 点击Update Project,勾选Force Update of Snapshots/Releases选项后确认。 - 清理项目缓存:点击顶部菜单栏
Project→ 选择Clean,选中你的项目执行清理即可。
完成上述操作后,JsonUtil导入报错会自动消失。
内容的提问来源于stack exchange,提问作者Justin
相关产品推荐
相关产品推荐

