title: What happens when you return a particular spring bean to any consumer of a rest endpoint
body: <p>I have a project with several spring boot modules.  Our data layer is not the simpler, more typical situation of CRUD and finders for model objects, and there is more configuration and knowledge of metadata that is needed for services that interact with our data.  If I have a module that consolidates the configuration that is important to several of the other modules, and if I registered these instances as spring beans, what would happen if I returned them from a rest endpoint to consumers?  Let us say, for example, that one of these objects is a custom <code>MongoRepository</code> implementation.  Would the returned instance be functional?  If two modules called the endpoint to request the instance, would the instances be functional when they were deserialized at the consumer modules?  Is there a difference if the consumers are on different JVMs than the service that hosts the rest endpoints?</p>
  <p>I am unsure if the answer is as straightforward as it might seem when we consider what happens when a model object is sent by a rest controller and received by a consumer.  A repository includes an established connection to the database that may or may not be SSL.  With things like authentication and authorization, it seems like this approach would not be feasible, but I thought I would ask the question to make sure that I really understand this.  I am weighing this approach against creating this module as a library (jar) that I can include in the modules that need this configuration.  I suspect that I will only be able to do this with the jar/library method, though.</p>