NoClassDeffoundErr在本地部署正常运行时在docker中部署实例化MongoDB

时间:2019-07-06 05:24:28

标签: java mongodb maven docker intellij-idea

Mondodb映像由docker拉出,然后运行连接MongoDBClient的Java应用程序。它可以在本地系统上正常运行,但是在使用IntelliJIdea的docker中部署时会发生错误

我正在使用Git,travis,Docker测试devops。我正在使用intellij IDE。 Java应用程序正在连接mongoDB并提取一条记录。它可以在本地正确运行intellij,但不能在表示NoClassDeffoundErr的docker部署中使用。

import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoCollection;
import org.bson.Document;

public class App
{
public static void main(String[] args)
{
    // Connect to MongoDB on local system - we're using port 27000
    MongoClient mongoClient = new MongoClient("localhost", 27000);
    // Get a database - will create when we use it
    MongoDatabase database = mongoClient.getDatabase("mydb");
    // Get a collection from the database
    MongoCollection<Document> collection = 
    database.getCollection("test");
    // Create a document to store
    Document doc = new Document("name", "Kevin Chalmers")
            .append("class", "Software Engineering Methods")
            .append("year", "2018/19")
            .append("result", new Document("CW", 95).append("EX", 85));
    // Add document to collection
    collection.insertOne(doc);

    // Check document in collection
    Document myDoc = collection.find().first();
    System.out.println(myDoc.toJson());
}

}

0 个答案:

没有答案