【问题标题】:IBM MobileFirst Adapters with external libraries带有外部库的 IBM MobileFirst 适配器
【发布时间】:2017-06-07 13:09:38
【问题描述】:

在 IBM MobileFirst 8.0 中使用带有 java 适配器的外部库是否有任何限制?

当我添加guava 时,我的代码没有错误(mfpdev 适配器构建成功),但是在部署到我的服务器时它响应错误:

[ERROR] Failed to execute goal com.ibm.mfp:adapter-maven-plugin:8.0.2016082422:deploy (default-cli) on project X: The output of /mfpadmin/management-apis/2.0/runtimes/mfp/adapters is of type text/html, which is unsupported. Expected an output of type text/xml or application/xml or application/json. -> [Help 1]

但是当我在 pom(mvn 依赖项)中删除番石榴时,我能够部署适配器。我看到的问题也发生在其他一些库上。有没有使用这些库的选项?

mfpdev -v: 8.0.0-2017012016

编辑:我终于通过在 pom 文件中设置番石榴的范围来解决问题:

<scope>provided</scope>

【问题讨论】:

  • 你是如何将它添加到 pom.xml 中的?
  • 通过 mvn 依赖。 &lt;!-- https://mvnrepository.com/artifact/com.google.guava/guava --&gt; &lt;dependency&gt; &lt;groupId&gt;com.google.guava&lt;/groupId&gt; &lt;artifactId&gt;guava&lt;/artifactId&gt; &lt;version&gt;21.0&lt;/version&gt; &lt;/dependency&gt;

标签: ibm-mobilefirst mobilefirst-adapters mobilefirst-cli


【解决方案1】:

我在我的 MFP 8.0 环境中尝试过,没有发现问题。

mfpdev -v
8.0.0-2017012016

0. Create  a sample Java adapter "mfpdev adapter create" 
1. Added dependency with guava 21 in pom.xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>

2. added a simple guava package and used it.

import com.google.common.base.Optional;

@GET

        @Produces(MediaType.TEXT_PLAIN)
        public String getResourceData() {
                // log message to server log
                logger.info("Logging info message...");
                Integer invalidInput = new Integer(20);
      Optional<Integer> a =  Optional.of(Input);
      Optional<Integer> b =  Optional.of(new Integer(10));
      logger.info("Logging my message with guava");
      );
        return "Hello from guava resource "+sum(a,b) ;
       }

4. build, deploy went successful

5. Access above resource 

Request URL

http://localhost:9080/mfp/api/adapters/testGuavaAdapter/resource

Response Body

Hello from guava resource 30

Response Code

200

Response Headers

{
  "x-powered-by": "Servlet/3.1",
  "content-type": "text/plain",
  "date": "Thu, 08 Jun 2017 11:48:32 GMT",
  "content-length": "28"
}

根据您的环境验证此工作 pom。

【讨论】:

  • 我的问题总是在我依赖番石榴时出现,即使我没有在 java 代码中使用它。如果我注释掉 guava 的依赖项,我可以毫无问题地部署适配器,但是当我添加这个依赖项时,我不能。 ``
  • 正如您在上面看到的,我添加了依赖项并且它可以工作,我使用的 MFP 服务器版本是最新的 MFP8 产品版本:8.0.0.00-20170412-235541。您能否确认使用的 MFP 服务器版本以及是否以与我在 pom.xml 中的 hv 相同的方式添加依赖项?
  • 我相信。我终于通过设置 scope:provided for dependency 解决了问题。
  • 好的,您还继续使用 21.0 吗?范围:提供了吗?
猜你喜欢
  • 2020-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多