简体   繁体   中英

Heroku Spring boot + Mongo DB on atlas

I am getting Null pointer exception while deploying my application on Heroku, from the exception log

    2021-01-28T23:18:59.561585+00:00 app[web.1]: Caused by: java.lang.NullPointerException: null
2021-01-28T23:18:59.561585+00:00 app[web.1]:    at com.mongodb.ConnectionString.<init>(ConnectionString.java:285) ~[mongodb-driver-core-3.11.2.jar!/:na]
2021-01-28T23:18:59.561585+00:00 app[web.1]:    at com.mongodb.client.MongoClients.create(MongoClients.java:61) ~[mongodb-driver-3.11.2.jar!/:na]
2021-01-28T23:18:59.561585+00:00 app[web.1]:    at com.shop.MongoConfiguration.mongoClient(MongoConfiguration.java:34) ~[classes!/:0.0.1-SNAPSHOT]
2021-01-28T23:18:59.561586+00:00 app[web.1]:    at

which looks like the application is not reading my application.properties file

spring.data.mongodb.uri=mongodb+srv://****
spring.data.mongodb.database=****

The application is working file on local env

Any idea how to overcome this issue?

issue solved by adding the below to pom.xml file

      <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        <resource>
                <directory>src/main/java</directory>
            <includes>
                    <include>*.properties</include>
                </includes>
            </resource>
        </resources>

as maven was ignoring copying the application.properties file inside the java directory

    remote:        [INFO] Scanning for projects...
    remote:        [INFO]
    remote:        [INFO] ------------------------------------------------------------------------
    remote:        [INFO] Building e-commerce 0.0.1-SNAPSHOT
    remote:        [INFO] ------------------------------------------------------------------------
    remote:        [INFO]
    remote:        [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ e-commerce ---
    remote:        [INFO] 
    remote:        [INFO] --- maven-dependency-plugin:3.1.2:list (default-cli) @ e-commerce ---
    remote:        [INFO] 
    remote:        [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ e-commerce ---
    remote:        [INFO] Using 'UTF-8' encoding to copy filtered resources.
    remote:        [INFO] Copying 16 resources
    remote:        [INFO] Copying 1 resource

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