title: Spring JPA PostgreSQL + MongoDB
body: <p>Starting from the Spring example <strong>Accessing MongoDB Data with REST</strong> (<a href="https://spring.io/guides/gs/accessing-mongodb-data-rest/" rel="nofollow">https://spring.io/guides/gs/accessing-mongodb-data-rest/</a>) I'd like to integrate a PostgreSQL data source and link it to the MongoDB repository.<br>By switching from <code>MongoRepository</code> to <code>JpaRepository</code> and accordingly changing the application.properties file I've been able to pass from MongoDB to PostgreSQL and viceversa, but basically having only one active data source at time.<br><br>
  <strong>application.properties when using MongoDB</strong></p>
  
  <pre><code>spring.data.mongodb.port=27017
  spring.data.mongodb.uri=mongodb://localhost/
  spring.data.mongodb.database=myMongoDB_DB
  spring.data.mongodb.repositories.enabled=true
  </code></pre>
  
  <p><br>
  <strong>application.properties when using PostgreSQL</strong></p>
  
  <pre><code>spring.datasource.driverClassName=org.postgresql.Driver
  spring.datasource.url=jdbc:postgresql://localhost:5432/myPostgreSQL_DB
  spring.datasource.username=me
  spring.datasource.password=mySuperSecretPassword
  
  spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
  spring.jpa.generate-ddl=true
  spring.jpa.show-sql=true
  spring.jpa.hibernate.ddl-auto=create
  </code></pre>
  
  <p>Is there a way to configure Spring (with an <strong>Annotation-only</strong> way) to link two data sources to the same Repository  so that when I access my REST web service via HTTP both MongoDB and PostgreSQL are changed in exactly the same way?<br><br>I googled around and found something about Spring cross-store support (<a href="http://docs.spring.io/spring-data/mongodb/docs/1.5.5.RELEASE/reference/html/mongo.cross.store.html" rel="nofollow">http://docs.spring.io/spring-data/mongodb/docs/1.5.5.RELEASE/reference/html/mongo.cross.store.html</a>) but it uses xml for the application configuration and AspectJ, is there a simpler way to accomplish this?</p>