spring data mongodb 配置遇到的几个问题
一. mongodb 2.2版本以上的配置
spring.data.mongodb.uri = mongodb://newlook:newlook@192.168.0.109:27017/admin
2.2及以下版本的配置
#spring.data.mongodb.host = 192.168.0.109
#spring.data.mongodb.username = newlook
#spring.data.mongodb.password = newlook
#spring.data.mongodb.defaultDB = admin
#spring.data.mongodb.port = 27017
二. Configuration
@Bean
PlatformTransactionManager platformTransactionManager() {
return new org.springframework.integration.transaction.PseudoTransactionManager();
}
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</dependency>
开始注入了其他的类型的TransactionManager,导致maven中自动引入了jpa相关的依赖,报错如下:
Caused by: java.lang.IllegalStateException: Cannot load driver class: mongodb.jdbc.MongoDriver
原因:
You seem to be trying to mix JPA, which is primarily intended for relational datastores, with MongoDB, which is an "unrelated" document store. Drop the dependency on spring-boot-starter-data-jpa (you simply don't need it) and the spring.datasource.driver-class-name (you should use MongoDB natively, not via a JDBC bridge).
三.org.springframework.dao.OptimisticLockingFailureException: Optimistic lock exception on saving entity
原因:版本控制的类型须为包装类型,
将
@Version
private int version;
改为:
@Version
private Integer version;
四.数据保存时候id总是empty
原因:ui中id提交时为“”,
将
<input th:field="*{id}" type="hidden"/>
改为:
<input th:field="*{id}" type="hidden" th:disabled="*{id==null}"/>
这样id提交后为null,可自动生成id
相关文档
http://docs.spring.io/spring-data/data-mongo/docs/1.9.2.RELEASE/reference/html/#query-by-example
https://docs.mongodb.com/manual/reference/command/
http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#a-menu-for-our-home-page
spring data mongodb 配置遇到的几个问题的更多相关文章
- spring data mongodb中,如果对象中的属性不想加入到数据库字段中
spring data mongodb中,如果对象中的属性不想加入到数据库字段中,可加@Transient注解,声明为透明属性 spring data mongodb 官网帮助文档 http://ww ...
- Spring data mongodb @CreatedBy@LastModifiedBy@CreatedBy@LastModifiedBy SpringSecurityAuditorAware,只记录用户名
要在Spring data mongodb 中使用@CreatedBy@LastModifiedBy@CreatedBy@LastModifiedBy 这四个注解 必须实现 SpringSecuri ...
- Spring Data MongoDB 一:入门篇(环境搭建、简单的CRUD操作)
一.简介 Spring Data MongoDB 项目提供与MongoDB文档数据库的集成.Spring Data MongoDB POJO的关键功能区域为中心的模型与MongoDB的DBColle ...
- Spring Data MongoDB example with Spring MVC 3.2
Spring Data MongoDB example with Spring MVC 3.2 Here is another example web application built with S ...
- 使用Spring访问Mongodb的方法大全——Spring Data MongoDB查询指南
1.概述 Spring Data MongoDB 是Spring框架访问mongodb的神器,借助它可以非常方便的读写mongo库.本文介绍使用Spring Data MongoDB来访问mongod ...
- Spring data mongodb 聚合,投射,内嵌数组文档分页.
尽量别直接用 DBObject ,Spring data mongodb 的api 本来就没什么多大用处,如果还直接用 DBObject 那么还需要自己去解析结果,说动做个对象映射,累不累 Spri ...
- JAVA 处理 Spring data mongodb 时区问题
Spring data mongodb 查询出结果的时候会自动 + 8小时,所以我们看起来结果是对的 但是我们查询的时候,并不会自动 + 8小时,需要自己处理 解决方法 1 @JsonFormat ...
- Spring data mongodb ObjectId ,根据id日期条件查询,省略@CreatedDate注解
先看看ObjectId 的json 结构,非常丰富,这里有唯一机器码,日期,时间戳等等,所以强烈建议ID 使用 ObjectId 类型,并且自带索引 Spring data mongodb 注解 @C ...
- Spring Data MongoDB 三:基本文档查询(Query、BasicQuery)(一)
一.简单介绍 Spring Data MongoDB提供了org.springframework.data.mongodb.core.MongoTemplate对MongoDB的CRUD的操作,上一 ...
随机推荐
- Spark机器学习读书笔记-CH03
3.1.获取数据: wget http://files.grouplens.org/datasets/movielens/ml-100k.zip 3.2.探索与可视化数据: In [3]: user_ ...
- Asp.net MVC路由机制
C:/Windows/Microsoft.NET/Framwork/v4.0.30319/config/web.config-> httpModules-> System.Web.Rout ...
- 去除 UINavigationController.navigationBar下方的横线
self.navigationController.navigationBar.clipsToBounds=YES;
- Visual Studio 2015 Update 1 ISO
Visual Studio Community 2015 with UPDATE 1___________________________________________English ENU - h ...
- Android 数据库管理— — —创建数据库
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...
- JPA 各种基本用法
查询部分属性 通常来说,都是针对 Entity 类的查询,返回的也是被查询的 Entity 类的实体.J P QL 也允许我们直接查询返回我们需要的属性,而不是返回整个 Entity .在一些 Ent ...
- 设置Ubuntu为本地时间
大家在切换操作系统的时候会发现一个问题, Windows 和 Ubuntu 的时间会出现不一致的情况.在 Windows 中把时间设置正确了过后,回到在 Ubuntu 后系统的时间又不一样了,在 Ub ...
- Junity测试最大子数列和的Java程序
1.Java环境的安装与配置: Jdk的安装: Jdk下载链接:http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-13 ...
- 长沙市轨道交通工程BIM应用招标公告
摘要: 长沙市轨道交通集团有限公司对其长沙市轨道交通3号线一期工程建筑信息模型(BIM)技术应用项目进行国内公开招标 长沙市轨道交通集团有限公司对其长沙市轨道交通3号线一期工程建筑信息模型(BIM)技 ...
- 查出重复的数据---------oracle
select chcod, count(1) from a group by chcod having count(1) > 1