@EnableMongoAuditing for MongoDB on Cloud Foundry / mongolab

后端 未结 1 1387
感情败类
感情败类 2021-01-25 19:50

My setup works on my local but not when I deploy it to CloudFoundry/mongolab.

The config is very similar to the docs.

My local spring config



        
相关标签:
1条回答
  • 2021-01-25 20:10

    This is usually caused if the Mongo mapping metadata obtained for entities does not scan entities at application startup. By default, AbstractMongoConfiguration uses the package of the actual configuration class to look for @Document annotated classes at startup.

    The exception message makes me assume that SpringCloudMongoDBConfiguration is not located in any of the super packages of com.foo.model.project. There are two solutions to this:

    • Stick to the convenience of putting application configuration classes into the root package of your application. This will cause your application packages be scanned for domain classes, metadata obtained, and the is-new-detection work as expected.
    • Manually hand the package containing domain classes to the infrastructure by overriding MongoConfiguration.getMappingBasePackage().

    The reason you might see the configuration working in the local environment is that the mapping metadata might be obtained through a non-persisting persistence operation (e.g. a query) and everything else proceeding from there.

    0 讨论(0)
提交回复
热议问题