package Ġcom . strat ix . demo . mongo Ċ Ċ import Ġcom . mongodb . Mongo Client Ċ import Ġorg . springframework . beans . factory . BeanFactory Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . cloud . config . java . Abstract Cloud Config Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Configuration Ċ import Ġorg . springframework . context . annotation . Profile Ċ import Ġorg . springframework . data . mongodb . Mongo Db Factory Ċ import Ġorg . springframework . data . mongodb . config . Abstract Mongo Configuration Ċ import Ġorg . springframework . data . mongodb . core . Mongo Template Ċ import Ġorg . springframework . data . mongodb . core . convert . Default Db Ref Resolver Ċ import Ġorg . springframework . data . mongodb . core . convert . Mapping Mongo Converter Ċ import Ġorg . springframework . data . mongodb . core . convert . Mongo Custom Conversions Ċ import Ġorg . springframework . data . mongodb . core . mapping . Mongo Mapping Context Ċ import Ġorg . springframework . data . mongodb . repository . config . Enable Mongo Repositories Ċ import Ġjava . util .* Ċ Ċ @ Profile (" ! cloud ") Ċ @ Configuration Ċ @ Enable Mongo Repositories Ċ class ĠMongo Config Ġ: ĠAbstract Mongo Configuration () Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġget Database Name () Ġ= Ġ" strat ix " ĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġoverride Ġfun Ġmongo Client () Ġ= ĠMongo Client (" localhost ") ĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġoverride Ġfun Ġmongo Template () Ġ= ĠMongo Template ( mongo Client (), Ġdatabase Name ) Ċ } Ċ Ċ @ Profile (" cloud ") Ċ @ Configuration Ċ @ Enable Mongo Repositories Ċ class ĠCloud Mongo Configuration : ĠAbstract Cloud Config () Ġ{ ĊĊĠĠĠ Ġ@ Value ("\ ${ strat ix . mongo . service - name }") ĊĠĠĠ Ġval Ġmongo Db InstanceId : ĠString Ġ= Ġ" mongo - strat ix " ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġfun Ġmong Db Factory (): ĠMongo Db Factory Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġconnection Factory (). mongo Db Factory ( mongo Db InstanceId ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġfun Ġcustom Conversions (): ĠMongo Custom Conversions Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠMongo Custom Conversions ( mutable ListOf < Collections >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġ@ Throws ( Class NotFoundException :: class ) ĊĠĠĠ Ġfun Ġmongo Mapping Context (): ĠMongo Mapping Context Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcontext Ġ= ĠMongo Mapping Context () ĊĠĠĠĠĠĠĠ Ġcontext . set Simple Type Holder ( custom Conversions (). simple Type Holder ) ĊĠĠĠĠĠĠĠ Ġreturn Ġcontext ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġ@ Throws ( Class NotFoundException :: class ) ĊĠĠĠ Ġfun Ġmapping Mongo Converter ( bean Factory : ĠBean Factory ): ĠMapping Mongo Converter Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdb Ref Resolver Ġ= ĠDefault Db Ref Resolver ( mong Db Factory ()) ĊĠĠĠĠĠĠĠ Ġval Ġmapping Converter Ġ= ĠMapping Mongo Converter ( db Ref Resolver , Ġmongo Mapping Context ()) ĊĠĠĠĠĠĠĠ Ġmapping Converter . set Custom Conversions ( custom Conversions ()) ĊĠĠĠĠĠĠĠ Ġreturn Ġmapping Converter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġ@ Throws ( Class NotFoundException :: class ) ĊĠĠĠ Ġfun Ġmongo Template ( bean Factory : ĠBean Factory ): ĠMongo Template Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠMongo Template ( mong Db Factory (), Ġmapping Mongo Converter ( bean Factory )) ĊĠĠĠ Ġ} Ċ }