Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

Referring to more than one template in JavaConfig when using repositories

$
0
0
I'm trying to configure one app to use more than 2 data sources. I have seen examples of this using XML config, but cannot find any information for using with JavaConfig.

I have tried referencing the templates from the repository...
Code:

@Configuration
@EnableMongoRepositories(mongoTemplateRef="adminMongoTemplate")
public interface AdminSettingsRepository extends CrudRepository<SettingsData, String> {
        @Query("{ 'project' : ?0 }")
        Iterable<SettingsData> findByProject(String username);
}

I have also referenced the repository from the AppConfig.java where the template is method is...

Code:

@Configuration
@ImportResource("classpath:/security-context.xml")
@EnableMongoRepositories(basePackages="com.xxxxxx.xxxxxx.data.repositories")
public class AppConfig {

        public AppConfig() {
               
        }
       
        //Mongo Template Bean for admin DB
        public @Bean
        MongoTemplate adminMongoTemplate() throws Exception {
                return new MongoTemplate(mongoDbFactory("admin"));
        }

I'm at a loss as to how to make this work apart from NOT taking advantage of dependency injection. An assistance or pointers as to where to look would be most helpful.
Thanks

Viewing all articles
Browse latest Browse all 128

Trending Articles