Chexxo
Chexxo

Reputation: 21

Connect Spring roo project to Mongo database

I am new too roo and trying to create a simple app to push to Heroku. I have the app up and working on my localhost with a MongoDB running on the localhost as well. I added a MongoDB to the app in Heroku but it will not open on Heroku (the app not the DB). I don't know what the issue is but do I need to connect my app to the Heroku DB somehow? As in changing the database.properties file? I tried to test it locally using the Heroku DB by taking this URL (Which I can use to log into the DB just fine with mongoctl):

mongodb://heroku_app10830648:************************@ds047387.mongolab.com:4738/heroku_app10830648

and putting the info into the database.properties file:

#Updated at Wed Jan 09 19:16:49 MST 2013
#Wed Jan 09 19:16:49 MST 2013
mongo.database=heroku_app10830648
mongo.host=ds047387.mongolab.com
mongo.password=***********************
mongo.port=47387
mongo.username=heroku_app10830648

but when I build it with mvn package I get this error:


T E S T S

Results:

Tests in error:

  testFindNotebook(com.xebia.shortnotes.domain.NotebookIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.notebook lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testFindAllNotebooks(com.xebia.shortnotes.domain.NotebookIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.notebook lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testFindNotebookEntries(com.xebia.shortnotes.domain.NotebookIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.notebook lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testSaveNotebook(com.xebia.shortnotes.domain.NotebookIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.notebook lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testDeleteNotebook(com.xebia.shortnotes.domain.NotebookIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.notebook lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testCountAllNotes(com.xebia.shortnotes.domain.NoteIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.note lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testFindNote(com.xebia.shortnotes.domain.NoteIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.note lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testFindAllNotes(com.xebia.shortnotes.domain.NoteIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.note lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testFindNoteEntries(com.xebia.shortnotes.domain.NoteIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.note lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testSaveNote(com.xebia.shortnotes.domain.NoteIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.note lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}
  testDeleteNote(com.xebia.shortnotes.domain.NoteIntegrationTest): command failed [command failed [count] { "assertion" : "unauthorized db:heroku_app10830648 ns:heroku_app10830648.note lock type:0 client:71.208.224.103" , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" : 0.0}

Tests run: 14, Failures: 0, Errors: 12, Skipped: 0

[INFO] ------------------------------------------------------------------------

[ERROR] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] There are test failures.

How do I use a different DB besides local in a mvn project.

Upvotes: 1

Views: 294

Answers (1)

Ben
Ben

Reputation: 11

[This post seems to be dormant, but I just ran into the same problem, and this is the top match in Google.]

I'm using a Spring/Roo/Mongo application which worked fine in "dev" mode, but when deployed to a cloud provider (OpenShift, CloudBees, Heroku, etc) and connecting to MongoHQ, the DB connections fail with the message:

command failed [command failed [count] { "ok" : 0.0 , "errmsg" : "unauthorized"}

Turns out the problem is in the auto-generated applicationContext-mongo.xml file. You need to add the username and password attributes:

<mongo:db-factory dbname="${mongo.name}" host="${mongo.host}" id="mongoDbFactory" port="${mongo.port}" username="${mongo.username}" password="${mongo.password}"/>

Here's a (likely outdated) link to the official docs (if it helps): http://static.springsource.org/spring-data/data-mongo/docs/1.0.0.M5/reference/html/#d0e1210

One other tip: use spring.profiles.active to make your application select the correct credentials/configuration based on the dev-mode, or running within a specific cloud provider. It would be really nice if each PaaS would define a Java System Property like "current.paas=heroku" to make auto-configuration easier.

Upvotes: 1

Related Questions