001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.data.mongo;
018
019import com.mongodb.MongoClient;
020
021import org.springframework.boot.autoconfigure.AutoConfigureAfter;
022import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
023import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
024import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
025import org.springframework.boot.autoconfigure.data.ConditionalOnRepositoryType;
026import org.springframework.boot.autoconfigure.data.RepositoryType;
027import org.springframework.context.annotation.Configuration;
028import org.springframework.context.annotation.Import;
029import org.springframework.data.mongodb.repository.MongoRepository;
030import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
031import org.springframework.data.mongodb.repository.config.MongoRepositoryConfigurationExtension;
032import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
033
034/**
035 * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Mongo
036 * Repositories.
037 * <p>
038 * Activates when there is no bean of type
039 * {@link org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean}
040 * configured in the context, the Spring Data Mongo
041 * {@link org.springframework.data.mongodb.repository.MongoRepository} type is on the
042 * classpath, the Mongo client driver API is on the classpath, and there is no other
043 * configured {@link org.springframework.data.mongodb.repository.MongoRepository}.
044 * <p>
045 * Once in effect, the auto-configuration is the equivalent of enabling Mongo repositories
046 * using the
047 * {@link org.springframework.data.mongodb.repository.config.EnableMongoRepositories}
048 * annotation.
049 *
050 * @author Dave Syer
051 * @author Oliver Gierke
052 * @author Josh Long
053 * @see EnableMongoRepositories
054 */
055@Configuration
056@ConditionalOnClass({ MongoClient.class, MongoRepository.class })
057@ConditionalOnMissingBean({ MongoRepositoryFactoryBean.class,
058                MongoRepositoryConfigurationExtension.class })
059@ConditionalOnRepositoryType(store = "mongodb", type = RepositoryType.IMPERATIVE)
060@Import(MongoRepositoriesAutoConfigureRegistrar.class)
061@AutoConfigureAfter(MongoDataAutoConfiguration.class)
062public class MongoRepositoriesAutoConfiguration {
063
064}