Java MongoDB身份验证和Apache Camel问题

Java MongoDB身份验证和Apache Camel问题,java,spring,mongodb,maven,apache-camel,Java,Spring,Mongodb,Maven,Apache Camel,我的MongoDb连接有问题。我正在mongo上使用Camel,我尝试在没有身份验证的情况下连接,然后连接就可以了。但是,当我尝试使用身份验证连接Mongo时,它不起作用 我的处理器是(没问题): 以及我的应用程序配置(无mongo auth): <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="h

我的MongoDb连接有问题。我正在mongo上使用Camel,我尝试在没有身份验证的情况下连接,然后连接就可以了。但是,当我尝试使用身份验证连接Mongo时,它不起作用

我的处理器是(没问题):

以及我的应用程序配置(无mongo auth):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camel:camelContext id="camel-client">
        <camel:routeBuilder ref="vinodroute"/>
    </camel:camelContext>

    <bean id="mongoBean" class="com.mongodb.MongoClient">
        <constructor-arg name="host" value="localhost" />
        <constructor-arg name="port" value="27017" />
    </bean>

    <bean id="jetty" class="org.apache.camel.component.jetty8.JettyHttpComponent8"/>
    <bean id="vinodroute" class="camel.venta.CamelMongoRoute"/>
    <bean id="camelProcessor" class="camel.venta.CamelProcessor"/>
</beans>


问题是,我如何将mongo与Autotension连接起来?

您可以使用
MongoClient
对象来创建
MongoClient

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camel:camelContext id="camel-client">
        <camel:routeBuilder ref="vinodroute"/>
    </camel:camelContext>

    <bean id="mongoBean" class="com.mongodb.MongoClient">
        <constructor-arg>
            <ref bean="mongoClientURI" />
        </constructor-arg>
    </bean>

    <bean id="mongoClientURI" class="com.mongodb.MongoClientURI">
        <constructor-arg name="uri" value="mongodb://username:password@localhost/eicas" />
    </bean>

    <bean id="jetty" class="org.apache.camel.component.jetty8.JettyHttpComponent8"/>
    <bean id="vinodroute" class="camel.venta.CamelMongoRoute"/>
    <bean id="camelProcessor" class="camel.venta.CamelProcessor"/>
</beans>


谢谢!这是工作!!!!我很高兴!!!我还有一个问题。如果相同的配置,我想更改Mongo的端口,我怎么做?mongodb://username:password@localhost:12345/eicastanks供您快速回答
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camel:camelContext id="camel-client">
        <camel:routeBuilder ref="vinodroute"/>
    </camel:camelContext>

    <bean id="mongoBean" class="com.mongodb.MongoClient">
        <constructor-arg>
            <ref bean="mongoClientURI" />
        </constructor-arg>
    </bean>

    <bean id="mongoClientURI" class="com.mongodb.MongoClientURI">
        <constructor-arg name="uri" value="mongodb://username:password@localhost/eicas" />
    </bean>

    <bean id="jetty" class="org.apache.camel.component.jetty8.JettyHttpComponent8"/>
    <bean id="vinodroute" class="camel.venta.CamelMongoRoute"/>
    <bean id="camelProcessor" class="camel.venta.CamelProcessor"/>
</beans>