简体   繁体   中英

Deploying a jHipster with MongoDB app to Heroku, with ObjectRocket addon

I have created a jHipster application that uses a MongoDB database. I am trying for the last few days to deploy it on Heroku. I've run the heroku generator as required. "jhipster heroku". I also pushed the code to the heroku branch with "git push heroku master". However, I still have a problem.

Caused by:

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoDbFactorySupport]: Factory method 'mongoDbFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.MongoClient]: Factory method 'mongo' threw exception; nested exception is java.lang.IllegalArgumentException: The connection string is invalid. Connection strings must start with either 'mongodb://' or 'mongodb+srv://

I do realize that I have to place the MongoDB connection string, provided by the ObjectRocket addon, somewhere in the.yml files, but I am not sure where. This is not a duplicate of Deploying a JHipster/MongoDB application to Heroku because that question was asked 5 years ago and since then, Heroku provided a subgenerator for MongoDB apps on Heroku. Also, should I modify the Profile somehow?

Thanks a lot for the help!

JHipster should have generated a application-heroku.yml under src/main/resources . It should contain the spring data property for the mongo db connection ( spring.data.mongodb.uri ). You should replace the value with your object rocket connection string.

Side note, why you have the errors message: JHipster uses only add-ons with a free tier. For mongo db it was mLab's addon. Sadly it has been discontinued. There is an open issue to update JHipster's heroku integration accordingly. https://github.com/jhipster/generator-jhipster/issues/13424

I managed to solve it finally. I suspected it due to the application-heroku.yml file. But this was not the only problem for me. The main problem was that I didn;t knew I have to edit the Procfile also. Tip for anyone that lands here. You should check that the Procfile is also edited with the database name.

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