【问题标题】:insert into database with anypoint studio使用 anypoint studio 插入数据库
【发布时间】:2015-05-28 15:12:29
【问题描述】:

我想将来自这个 json 文件的流:https://gist.githubusercontent.com/Rajeun/3dbbe8ca240d479dbabe/raw/aba5d0ec9345b886426ab767376b7c9cb60c251f/person.json 保存在使用 anypoint studio 的数据库中。

为此,我使用了一个 http 连接器,其中我提到了 json 文件的链接。然后我使用了一个 json-to-object 转换器和一个数据库连接器。 在我的数据库中,我有一个带有 id、token、tel“int”的表,而 email 是一个 varchar -(我测试了连接及其工作良好)。 当我运行我的代码时:

ERROR 2015-03-20 13:14:05,522 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
java.lang.NullPointerException
    at org.mule.module.db.internal.config.domain.query.QueryTemplateBeanDefinitionParser.parseParameterizedQuery(QueryTemplateBeanDefinitionParser.java:136) ~[mule-module-db-3.6.1.jar:3.6.1]
    at org.mule.module.db.internal.config.domain.query.QueryTemplateBeanDefinitionParser.doParse(QueryTemplateBeanDefinitionParser.java:62) ~[mule-module-db-3.6.1.jar:3.6.1]
    at org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser.parseInternal(AbstractMuleBeanDefinitionParser.java:295) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
    at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.parseCustomElement(MuleHierarchicalBeanDefinitionParserDelegate.java:98) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
    at org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.parseCustomElement(MuleHierarchicalBeanDefinitionParserDelegate.java:140) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
    ******************************************************************************

配置:

  <mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
    http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
        <http:listener-config name="HTTP_Listener_Configuration" host="www.gist.githubusercontent.com" port="80" doc:name="HTTP Listener Configuration"/>
        <db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" database="mulesoft" doc:name="MySQL Configuration"/>
        <db:template-query name="Template_Query" doc:name="Template Query">
            <db:parameterized-query/>
        </db:template-query>
        <flow name="testFlow">
            <http:listener config-ref="HTTP_Listener_Configuration" path="Rajeun/3dbbe8ca240d479dbabe/raw/aba5d0ec9345b886426ab767376b7c9cb60c251f/person.json" doc:name="HTTP"/>
            <json:json-to-object-transformer returnClass="myclass" doc:name="JSON to Object"/>
            <response>
                <logger message="c bon" level="INFO" doc:name="Logger"/>
            </response>
            <response>
                <db:insert config-ref="MySQL_Configuration" doc:name="Database">
                    <db:parameterized-query><![CDATA[INSERT INTO push(id, token, tel, email) VALUES (2,2,3,#[payload['userImage']])]]></db:parameterized-query>
                </db:insert>
            </response>
        </flow>
    </mule>

【问题讨论】:

  • 应该有一个堆栈跟踪显示部署失败的原因。指出您的配置有问题。请发布此内容和您的配置。
  • 错误 2015-03-20 10:37:00,163 [main] org.mule.module.launcher.application.DefaultMuleApplication: null java.lang.NullPointerException
  • INFO 2015-03-20 10:37:00,164 [main] org.mule.module.launcher.application.DefaultMuleApplication:应用程序“测试”从未启动,没有什么可处理的错误 2015-03- 20 10:37:00,500 [主] org.mule.module.launcher.DefaultArchiveDeployer:+++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ + 部署工件“测试”失败,见下文 +
  • 引起:org.mule.api.config.ConfigurationException:从 URL [file:/C:/Users/Rajeun/AnypointStudio/workspace/.mule/apps/test/ 解析 XML 文档时出现意外异常测试.xml];嵌套异常是 java.lang.NullPointerException (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException)

标签: json mule esb


【解决方案1】:

删除空模板查询:

<db:template-query name="Template_Query" doc:name="Template Query">
   <db:parameterized-query />
</db:template-query>

另外,'myclass' 存在吗?如果不尝试仅使用地图:

<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>

此外,您似乎想从指定的 URL 检索该 JSON 文件。为此,您需要 http:request 而不是 http:listener。 http:listener 用作等待应用请求的消息源。

您应该使用 http:request 来请求文件并使用轮询消息源触发它:

<http:request-config name="HTTP_Request_Configuration" host="www.gist.githubusercontent.com" port="80" doc:name="HTTP Request Configuration"/>


 <flow name="testFlow">
    <poll>
        <http:request config-ref="HTTP_Request_Configuration" path="Rajeun/3dbbe8ca240d479dbabe/raw/aba5d0ec9345b886426ab767376b7c9cb60c251f/person.json" method="GET" doc:name="HTTP"/>
    </poll>

</flow>

见:http://www.mulesoft.org/documentation/display/current/HTTP+Request+Connector 还有:http://www.mulesoft.org/documentation/display/current/Poll+Reference

【讨论】:

  • 感谢您的回复。好吧,它给出了新的例外: java.io.IOException org.mule.api.config.ConfigurationException org.mule.api.lifecycle.InitialisationException org.springframework.beans.factory.BeanCreationException org.mule.api.lifecycle.InitialisationException: org. mule.api.MuleRuntimeException
  • 再次,我需要完整的堆栈跟踪。你能把它上传到 pastebin 或类似的东西吗?
  • 感觉少了点什么:我也得到了这个异常: Caused by: java.lang.ClassNotFoundException: Cannot load class 'myclass'
  • 你有一个名为“myclass”的课程吗?如果不尝试使用地图。查看我的更新答案
  • 是的,检查我更新的答案。将 returnClass 替换为正确的完全限定类或使用映射。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多