简体   繁体   中英

Why does MongoDB maven dependency cannot be added with runtime scope?

Why does MongoDB maven dependency cannot be added as runtime whereas for all the other databases it works without any issues ?

pom.xml

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>7.0</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.1.0</version>
</dependency>

Please guide.

Because for oracle you use the jdbc API which oracle only implement (unless you are using oracle SQL types for example).

You are only using The Connection , Statement , ResultSet and in runtime you obtain an Oracle Connection, probably using a container managed connection pool.

You don't compile your code (again, usually) with classes taken from ojdbc7 jar. The jdbc interfaces and classes are part of the jre.

Whereas with mongodb, you code and compile with specific classes and interfaces taken from the mongo-java-driver jar (and jars it depends on). Classes such as MongoClient , Document etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM