1. 程式人生 > >Spring Boot Mongodb

Spring Boot Mongodb

Spring註解學習,有助於更好的理解下面程式碼:

  • @ConditionOnClass表明該@Configuration僅僅在一定條件下才會被載入,這裡的條件是Mongo.class位於類路徑上
  • @EnableConfigurationProperties將Spring Boot的配置檔案(application.properties)中的spring.data.mongodb.*屬性對映為MongoProperties並注入到MongoAutoConfiguration中。
  • @ConditionalOnMissingBean說明Spring Boot僅僅在當前上下文中不存在Mongo物件時,才會例項化一個Bean。這個邏輯也體現了Spring Boot的另外一個特性——自定義的Bean優先於框架的預設配置,我們如果顯式的在業務程式碼中定義了一個Mongo
    物件,那麼Spring Boot就不再建立。

一、先看看spring boot mongo部分原始碼片段

/*
 * Copyright 2012-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.autoconfigure.mongo;

import java.net.UnknownHostException;

import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;

/**
 * {@link EnableAutoConfiguration Auto-configuration} for Mongo.
 *
 * @author Dave Syer
 * @author Oliver Gierke
 * @author Phillip Webb
 */
@Configuration
@ConditionalOnClass(MongoClient.class)
@EnableConfigurationProperties(MongoProperties.class)
@ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory")
public class MongoAutoConfiguration {

	@Autowired
	private MongoProperties properties;

	@Autowired(required = false)
	private MongoClientOptions options;

	@Autowired
	private Environment environment;

	private MongoClient mongo;

	@PreDestroy
	public void close() {
		if (this.mongo != null) {
			this.mongo.close();
		}
	}

	@Bean
	@ConditionalOnMissingBean
	public MongoClient mongo() throws UnknownHostException {
		this.mongo = this.properties.createMongoClient(this.options, this.environment);
		return this.mongo;
	}

}
/*
 * Copyright 2012-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.autoconfigure.mongo;

import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.annotation.Persistent;
import org.springframework.data.mapping.model.FieldNamingStrategy;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.core.convert.CustomConversions;
import org.springframework.data.mongodb.core.convert.DbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;

/**
 * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's mongo support.
 * <p>
 * Registers a {@link MongoTemplate} and {@link GridFsTemplate} beans if no other beans of
 * the same type are configured.
 * <P>
 * Honors the {@literal spring.data.mongodb.database} property if set, otherwise connects
 * to the {@literal test} database.
 *
 * @author Dave Syer
 * @author Oliver Gierke
 * @author Josh Long
 * @author Phillip Webb
 * @author Eddú Meléndez
 * @since 1.1.0
 */
@Configuration
@ConditionalOnClass({ Mongo.class, MongoTemplate.class })
@EnableConfigurationProperties(MongoProperties.class)
@AutoConfigureAfter(MongoAutoConfiguration.class)
public class MongoDataAutoConfiguration implements BeanClassLoaderAware {

	@Autowired
	private MongoProperties properties;

	@Autowired
	private Environment environment;

	@Autowired
	private ResourceLoader resourceLoader;

	private ClassLoader classLoader;

	@Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		this.classLoader = classLoader;
	}

	@Bean
	@ConditionalOnMissingBean(MongoDbFactory.class)
	public SimpleMongoDbFactory mongoDbFactory(MongoClient mongo) throws Exception {
		String database = this.properties.getMongoClientDatabase();
		return new SimpleMongoDbFactory(mongo, database);
	}

	@Bean
	@ConditionalOnMissingBean
	public MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory,
			MongoConverter converter) throws UnknownHostException {
		return new MongoTemplate(mongoDbFactory, converter);
	}

	@Bean
	@ConditionalOnMissingBean(MongoConverter.class)
	public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory,
			MongoMappingContext context, BeanFactory beanFactory) {
		DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
		MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver,
				context);
		try {
			mappingConverter.setCustomConversions(beanFactory
					.getBean(CustomConversions.class));
		}
		catch (NoSuchBeanDefinitionException ex) {
			// Ignore
		}
		return mappingConverter;
	}

	@Bean
	@ConditionalOnMissingBean
	public MongoMappingContext mongoMappingContext(BeanFactory beanFactory)
			throws ClassNotFoundException {
		MongoMappingContext context = new MongoMappingContext();
		context.setInitialEntitySet(getInitialEntitySet(beanFactory));
		Class<? extends FieldNamingStrategy> strategyClass = this.properties
				.getFieldNamingStrategy();
		if (strategyClass != null) {
			context.setFieldNamingStrategy(BeanUtils.instantiate(strategyClass));
		}
		return context;
	}

	private Set<Class<?>> getInitialEntitySet(BeanFactory beanFactory)
			throws ClassNotFoundException {
		Set<Class<?>> entitySet = new HashSet<Class<?>>();
		ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
				false);
		scanner.setEnvironment(this.environment);
		scanner.setResourceLoader(this.resourceLoader);
		scanner.addIncludeFilter(new AnnotationTypeFilter(Document.class));
		scanner.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
		for (String basePackage : getMappingBasePackages(beanFactory)) {
			if (StringUtils.hasText(basePackage)) {
				for (BeanDefinition candidate : scanner
						.findCandidateComponents(basePackage)) {
					entitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
							this.classLoader));
				}
			}
		}
		return entitySet;
	}

	private static Collection<String> getMappingBasePackages(BeanFactory beanFactory) {
		try {
			return AutoConfigurationPackages.get(beanFactory);
		}
		catch (IllegalStateException ex) {
			// no auto-configuration package registered yet
			return Collections.emptyList();
		}
	}

	@Bean
	@ConditionalOnMissingBean
	public GridFsTemplate gridFsTemplate(MongoDbFactory mongoDbFactory,
			MongoTemplate mongoTemplate) {
		return new GridFsTemplate(new GridFsMongoDbFactory(mongoDbFactory,
				this.properties), mongoTemplate.getConverter());
	}

	/**
	 * {@link MongoDbFactory} decorator to respect
	 * {@link MongoProperties#getGridFsDatabase()} if set.
	 */
	private static class GridFsMongoDbFactory implements MongoDbFactory {

		private final MongoDbFactory mongoDbFactory;

		private final MongoProperties properties;

		public GridFsMongoDbFactory(MongoDbFactory mongoDbFactory,
				MongoProperties properties) {
			Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null");
			Assert.notNull(properties, "Properties must not be null");
			this.mongoDbFactory = mongoDbFactory;
			this.properties = properties;
		}

		@Override
		public DB getDb() throws DataAccessException {
			String gridFsDatabase = this.properties.getGridFsDatabase();
			if (StringUtils.hasText(gridFsDatabase)) {
				return this.mongoDbFactory.getDb(gridFsDatabase);
			}
			return this.mongoDbFactory.getDb();
		}

		@Override
		public DB getDb(String dbName) throws DataAccessException {
			return this.mongoDbFactory.getDb(dbName);
		}

		@Override
		public PersistenceExceptionTranslator getExceptionTranslator() {
			return this.mongoDbFactory.getExceptionTranslator();
		}

	}

}
/*
 * Copyright 2012-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.autoconfigure.mongo;

import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.data.mapping.model.FieldNamingStrategy;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientOptions.Builder;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;

/**
 * Configuration properties for Mongo.
 *
 * @author Dave Syer
 * @author Phillip Webb
 * @author Josh Long
 * @author Andy Wilkinson
 * @author Eddú Meléndez
 */
@ConfigurationProperties(prefix = "spring.data.mongodb")
public class MongoProperties {

	/**
	 * Default port used when the configured port is {@code null}.
	 */
	public static final int DEFAULT_PORT = 27017;

	/**
	 * Mongo server host.
	 */
	private String host;

	/**
	 * Mongo server port.
	 */
	private Integer port = null;

	/**
	 * Mongo database URI. When set, host and port are ignored.
	 */
	private String uri = "mongodb://localhost/test";

	/**
	 * Database name.
	 */
	private String database;

	/**
	 * Authentication database name.
	 */
	private String authenticationDatabase;

	/**
	 * GridFS database name.
	 */
	private String gridFsDatabase;

	/**
	 * Login user of the mongo server.
	 */
	private String username;

	/**
	 * Login password of the mongo server.
	 */
	private char[] password;

	/**
	 * Fully qualified name of the FieldNamingStrategy to use.
	 */
	private Class<? extends FieldNamingStrategy> fieldNamingStrategy;

	public String getHost() {
		return this.host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getDatabase() {
		return this.database;
	}

	public void setDatabase(String database) {
		this.database = database;
	}

	public String getAuthenticationDatabase() {
		return this.authenticationDatabase;
	}

	public void setAuthenticationDatabase(String authenticationDatabase) {
		this.authenticationDatabase = authenticationDatabase;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public char[] getPassword() {
		return this.password;
	}

	public void setPassword(char[] password) {
		this.password = password;
	}

	public Class<? extends FieldNamingStrategy> getFieldNamingStrategy() {
		return this.fieldNamingStrategy;
	}

	public void setFieldNamingStrategy(
			Class<? extends FieldNamingStrategy> fieldNamingStrategy) {
		this.fieldNamingStrategy = fieldNamingStrategy;
	}

	public void clearPassword() {
		if (this.password == null) {
			return;
		}
		for (int i = 0; i < this.password.length; i++) {
			this.password[i] = 0;
		}
	}

	public String getUri() {
		return this.uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public Integer getPort() {
		return this.port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public String getGridFsDatabase() {
		return this.gridFsDatabase;
	}

	public void setGridFsDatabase(String gridFsDatabase) {
		this.gridFsDatabase = gridFsDatabase;
	}

	public String getMongoClientDatabase() {
		if (this.database != null) {
			return this.database;
		}
		return new MongoClientURI(this.uri).getDatabase();
	}

	/**
	 * Creates a {@link MongoClient} using the given {@code options}
	 *
	 * @param options the options
	 * @return the Mongo client
	 * @throws UnknownHostException if the configured host is unknown
	 * @deprecated Since 1.3.0 in favour of
	 * {@link #createMongoClient(MongoClientOptions, Environment)}
	 */
	@Deprecated
	public MongoClient createMongoClient(MongoClientOptions options)
			throws UnknownHostException {
		return this.createMongoClient(options, null);
	}

	/**
	 * Creates a {@link MongoClient} using the given {@code options} and
	 * {@code environment}. If the configured port is zero, the value of the
	 * {@code local.mongo.port} property retrieved from the {@code environment} is used
	 * to configure the client.
	 *
	 * @param options the options
	 * @param environment the environment
	 * @return the Mongo client
	 * @throws UnknownHostException if the configured host is unknown
	 */
	public MongoClient createMongoClient(MongoClientOptions options,
			Environment environment) throws UnknownHostException {
		try {
			if (hasCustomAddress() || hasCustomCredentials()) {
				if (options == null) {
					options = MongoClientOptions.builder().build();
				}
				List<MongoCredential> credentials = null;
				if (hasCustomCredentials()) {
					String database = this.authenticationDatabase == null ? getMongoClientDatabase()
							: this.authenticationDatabase;
					credentials = Arrays.asList(MongoCredential.createMongoCRCredential(
							this.username, database, this.password));
				}
				String host = this.host == null ? "localhost" : this.host;
				int port = determinePort(environment);
				return new MongoClient(Arrays.asList(new ServerAddress(host, port)),
						credentials, options);
			}
			// The options and credentials are in the URI
			return new MongoClient(new MongoClientURI(this.uri, builder(options)));
		}
		finally {
			clearPassword();
		}
	}

	private boolean hasCustomAddress() {
		return this.host != null || this.port != null;
	}

	private boolean hasCustomCredentials() {
		return this.username != null && this.password != null;
	}

	private int determinePort(Environment environment) {
		if (this.port == null) {
			return DEFAULT_PORT;
		}
		if (this.port == 0) {
			if (environment != null) {
				String localPort = environment.getProperty("local.mongo.port");
				if (localPort != null) {
					return Integer.valueOf(localPort);
				}
			}
			throw new IllegalStateException(
					"spring.data.mongodb.port=0 and no local mongo port configuration "
							+ "is available");
		}
		return this.port;
	}

	private Builder builder(MongoClientOptions options) {
		Builder builder = MongoClientOptions.builder();
		if (options != null) {
			builder.alwaysUseMBeans(options.isAlwaysUseMBeans());
			builder.connectionsPerHost(options.getConnectionsPerHost());
			builder.connectTimeout(options.getConnectTimeout());
			builder.cursorFinalizerEnabled(options.isCursorFinalizerEnabled());
			builder.dbDecoderFactory(options.getDbDecoderFactory());
			builder.dbEncoderFactory(options.getDbEncoderFactory());
			builder.description(options.getDescription());
			builder.maxWaitTime(options.getMaxWaitTime());
			builder.readPreference(options.getReadPreference());
			builder.socketFactory(options.getSocketFactory());
			builder.socketKeepAlive(options.isSocketKeepAlive());
			builder.socketTimeout(options.getSocketTimeout());
			builder.threadsAllowedToBlockForConnectionMultiplier(options
					.getThreadsAllowedToBlockForConnectionMultiplier());
			builder.writeConcern(options.getWriteConcern());
		}
		return builder;
	}

}

------------------------------------------------------------------------------------------------------------------------------------------------------

以上為spring boot mongo的片段,可以看出spring boot已經配置好了,也就是說springboot啟動後@Bean建立的物件可以直接使用@Autowrite直接使用

關注點(spring boot啟動會直接讀取application.yml或者是application.properties,這裡我用的是yml)

@ConfigurationProperties(prefix = "spring.data.mongodb")
public class MongoProperties 

啟動入口

Applicaiton.java 

package com.modou.weixin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

/**
 * Created by chababa on 15/8/22.
 */
@Configuration
@ComponentScan(basePackages={"com.modou.conf","com.modou.weixin"})
@EnableAutoConfiguration
public class Application implements CommandLineRunner{
	@Autowired
	MongoTemplate template;
	
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		System.err.println(template != null);
	}
}
注入MongoTemplate結果

# SPRING PROFILES
spring:       
    # HTTP ENCODING
    http:
        encoding.charset: UTF-8
        encoding.enable: true
        encoding.force: true
    data:
        mongodb:
               host: 127.0.0.1
               port: 27017
               username: 
               password: 
               database: xx
               authenticationDatabase:  


相關推薦

spring boot MongoDB的整合和使用

前言 上一章節,簡單講解了如何整合Spring-data-jpa。本章節,我們來看看如何整合NoSQL的Mongodb。mongodb是最早熱門非關係資料庫的之一,使用也比較普遍。最適合來儲存一些非結構資料了,適合對大量或者無固定格式的資料進行儲存,比如:日誌、快取等。 一點知識

Spring Boot + MongoDB 入門的01 許可權的一些坑

1,mongodb預設是沒有許可權驗證的,執行時mongod --auth或更改設定開啟 2,首先新增管理員賬號 cmd mongo use admin db.createUser({user:"XXXX",pwd:"XXXXX",roles:[{"role"

spring boot+mongodb入門隨筆02 join操作$lookup

目的是要實現類似sql的join操作 參考$lookup public class OrderQsDemographicSize { @Id private String id; private String demographic; private L

Spring-boot mongodb ID自增長註解實現 適用於JDK 1.7和JDK 1.8

開發工具Idea ,JDK1.8 Entity類 SeqInfo.java package com.gl.springbootdao.mongodb.entity; import lombok.Getter; import lombok.Setter; import lombok.T

idea搭建spring boot+MongoDB+redis+mysql+activemq

1適合入門參照,比較全面,基於企業開發的最終極框架,全部所用最新版本(2018-10-26) 2加入對開發比較有好的BaseDAO 3反向生成實體類 1 new project 勾選: Core→DevTools(利於開發熱部署),Lombok(實體類不

Spring Boot + MongoDB 增刪改查的簡單使用

MongoDB簡介mongodb是一個介於nosql資料庫和mysql資料庫之間的一個數據儲存系統,它沒有嚴格的資料格式,但同時支援複雜查詢,而且自帶sharding模式和Replica Set模式,支援分片模式,複製模式,自動故障處理,自動故障轉移,自動擴容,全內容索引,動

spring boot mongodb 統計表中某一欄位的所有值,其中aggregate的用法之一

pom.xml 依賴: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb<

spring boot mongodb 整合以及簡單查詢(非實體結果返回)

一、安裝(nosql 視覺化工具客戶端下載路徑:https://nosqlbooster.com/downloads) 二、專案新增依賴 <dependency> <groupId>org.springframework.boot</groupId>

Spring Boot Mongodb

Spring註解學習,有助於更好的理解下面程式碼: @ConditionOnClass表明該@Configuration僅僅在一定條件下才會被載入,這裡的條件是Mongo.class位於類路徑上@EnableConfigurationProperties將Spring

Spring-boot mongodb ID自增長註解實現 適用於JDK 1.7和JDK 1.8

開發工具Idea ,JDK1.8 Entity類 SeqInfo.java package com.gl.springbootdao.mongodb.entity; import lombok.Getter; import lombok.Setter; import l

Spring Boot+MongoDB專案搭建

MongoDB是一個基於文件(Document)的儲存型的資料庫,使用面向物件的思想,每一條資料記錄都是文件的物件。 - 1.Spring對MongoDB的支援 Spring對MongoDB的支援主要是通過Spring Data MongoDB來實現的,

用 Docker 釋出來一個 Nginx+Spring Boot+MongoDB應用

專案構建於Maven,需要先在pom.xml中增加docker的plugin: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/

Spring boot 啟動報錯:com.mongodb.MongoSocketOpenException: Exception opening socket

clas cati helper res connect ava bstr efault def   詳細錯誤信息: com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.

springboot(十一):Spring bootmongodb的使用

gpo for 當前 window 公司 多表 erlang 大量 secondary mongodb是最早熱門非關系數據庫的之一,使用也比較普遍,一般會用做離線數據分析來使用,放到內網的居多。由於很多公司使用了雲服務,服務器默認都開放了外網地址,導致前一陣子大批 Mong

Spring Boot教程(三十五)使用MongoDB數據庫(1)

frame 既然 artifact html ace 數據庫 支持 高度 官網 MongoDB簡介 MongoDB是一個基於分布式文件存儲的數據庫,它是一個介於關系數據庫和非關系數據庫之間的產品,其主要目標是在鍵/值存儲方式(提供了高性能和高度伸縮性)和傳統的RDBMS系統

spring boot 使用 mongodb

mysq data tar con 妹子 只需要 插入 註解 存在 由於機器上沒有數據庫,裝個Mysql或者sql server比較麻煩,所以還是用mongodb來練手了(因為這邊不需要自己去導入驅動) 開始之前先確保環境沒問題 1. Maven 倉庫正確的配置 可以在cm

spring-boot整合mongodb的案例

  1.簡介 MongoDB 是一個基於分散式檔案儲存的資料庫。由 C++ 語言編寫。旨在為 WEB 應用提供可擴充套件的高效能資料儲存解決方案。 MongoDB 是一個介於關係資料庫和非關係資料庫之間的產品,是非關係資料庫當中功能最豐富,最像關係資料庫的。 2.執行環境

Spring Boot中使用MongoDB資料庫實戰

 一 MongoDB簡介 MongoDB是一個基於分散式檔案儲存的資料庫,它是一個介於關係資料庫和非關係資料庫之間的產品,其主要目標是在鍵/值儲存方式(提供了高效能和高度伸縮性)和傳統的RDBMS系統(具有豐富的功能)之間架起一座橋樑,它集兩者的優勢於一身。 MongoDB支援

mongoDb簡介和整合spring boot

MongoDb MongoDb是一種非關係型資料庫,是現在非常火熱的noSQL。也被稱為文件性資料庫。(可存放json,xml等格式) mongodb與mysql命令對比 傳統的關係資料庫一般由資料庫(database)、表(table)、記錄(record)三個層次概念組成, Mo

Java 讀取任意shapefile的所有欄位,並插入到MongoDB資料庫(Spring Boot

文章目錄 Java 讀取任意shapefile的所有欄位,並插入到MongoDB資料庫(Spring Boot) 1. 統一返回結果封裝 2. shp檔案資料實體封裝 3. 核心程式碼