/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoRepositoriesAutoConfiguration.java

https://gitlab.com/jimador/spring-boot · Java · 63 lines · 22 code · 5 blank · 36 comment · 0 complexity · 9ec66a21e4b1ef6eee4f82345da4ae13 MD5 · raw file

  1. /*
  2. * Copyright 2012-2015 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.boot.autoconfigure.data.mongo;
  17. import com.mongodb.Mongo;
  18. import org.springframework.boot.autoconfigure.AutoConfigureAfter;
  19. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  20. import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
  21. import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
  22. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  23. import org.springframework.context.annotation.Configuration;
  24. import org.springframework.context.annotation.Import;
  25. import org.springframework.data.mongodb.repository.MongoRepository;
  26. import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
  27. import org.springframework.data.mongodb.repository.config.MongoRepositoryConfigurationExtension;
  28. import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
  29. /**
  30. * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Mongo
  31. * Repositories.
  32. * <p>
  33. * Activates when there is no bean of type
  34. * {@link org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean}
  35. * configured in the context, the Spring Data Mongo
  36. * {@link org.springframework.data.mongodb.repository.MongoRepository} type is on the
  37. * classpath, the Mongo client driver API is on the classpath, and there is no other
  38. * configured {@link org.springframework.data.mongodb.repository.MongoRepository}.
  39. * <p>
  40. * Once in effect, the auto-configuration is the equivalent of enabling Mongo repositories
  41. * using the
  42. * {@link org.springframework.data.mongodb.repository.config.EnableMongoRepositories}
  43. * annotation.
  44. *
  45. * @author Dave Syer
  46. * @author Oliver Gierke
  47. * @author Josh Long
  48. * @see EnableMongoRepositories
  49. */
  50. @Configuration
  51. @ConditionalOnClass({ Mongo.class, MongoRepository.class })
  52. @ConditionalOnMissingBean({ MongoRepositoryFactoryBean.class,
  53. MongoRepositoryConfigurationExtension.class })
  54. @ConditionalOnProperty(prefix = "spring.data.mongodb.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
  55. @Import(MongoRepositoriesAutoConfigureRegistrar.class)
  56. @AutoConfigureAfter(MongoDataAutoConfiguration.class)
  57. public class MongoRepositoriesAutoConfiguration {
  58. }