小强哥博客

小强哥,小强哥博客,技术大咖

springboot 禁用mongoDB自动配置

一、问题背景

springboot 内置了mongoDB驱动,默认配置localhost:27017,若本机没有配置mongoDB,则会连接失败。

image

二、解决方案

  1. 添加注解:@SpringBootApplication(exclude = {MongoAutoConfiguration.class,MongoDataAutoConfiguration.class})
/*
 *   Copyright (c) 2016, inter3i.com. All rights reserved.
 *
 *   Author: dq
 *   Created: 11/18/16 6:01 PM
 *   Description:
 *
 */

package com.inter3i.sun.api.ota.v1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan
@SpringBootApplication(exclude = {MongoAutoConfiguration.class,MongoDataAutoConfiguration.class})
//在部署到外部的Tomcat时,需要将classpath的引入文件去掉,因为在web.xml已经配置过一次了
//@ImportResource("classpath:dispatcher-servlet.xml")
public class Application{
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

参考:http://blog.csdn.net/jxq0816/article/details/77504226?locationNum=8&fps=1