Log4j nosql appender无法对MongoDB服务器进行身份验证

时间:2015-07-02 06:57:50

标签: java mongodb maven log4j2

我正在尝试使用Apache Log4J NoSQL appender。我已将其配置为连接到我的MongoDB实例,但在使用Maven Install运行项目时,我似乎遇到了身份验证错误:

ERROR Failed to authenticate against MongoDB server. Unknown error.

我正在使用MongoDB 3.0.4并使用以下命令创建了以下用户:

use test
db.createUser({
    user:"logUser",
    pwd:"pwd",
    roles:["readWrite","dbAdmin"]
})

我已经检查过我可以使用以下方式连接:

mongo -u logUser -p pwd

我的log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
    <Appenders>
        <NoSql name="databaseAppender">
            <MongoDb databaseName="test" collectionName="logging" server = "localhost"
            port="27017" username = "logUser" password = "pwd"/>
        </NoSql>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="databaseAppender"/>
        </Root>
    </Loggers>
</Configuration>

以下是我的POM.xml配置更改:

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>2.12.3</version>
      </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-nosql</artifactId>
        <version>2.3</version>
    </dependency>   
</dependencies>   

0 个答案:

没有答案