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的操作,上一 ...
随机推荐
- io端口与io内存详解
(一)地址的概念 1)物理地址:CPU地址总线传来的地址,由硬件电路控制其具体含义.物理地址中很大一部分是留给内存条中的内存的,但也常被映射到其他存储器上(如显存.BIOS等).在程序指令中的虚拟地址 ...
- linux命令每日一练习 wc more
wc该命令统计文件行数,字数或者字节数 wc -l 统计行数 wc -w 统计字数 wc -c 统计字节数 more 显示文件内容,类似于cat more +n 从第n行开始显示 more -n 限定 ...
- Html标签第一课
<p>段落标签</p> <h1>字体标签,1到6,越来越小</h1>.....<h6></h6><h>标签自动换行 ...
- glibc与MSVC CRT(转载)
glibc与MSVC CRT 运行库是平台相关的,因为它与操作系统结合得非常紧密.C语言的运行库从某种程度上来讲是C语言的程序和不同操作系统平台之间的抽象层,它将不同的操作系统API抽象成相同的库函数 ...
- 灰常好的开源项目[c/c++]
ClibPDF http://cosoft.net.cn http://www2s.biglobe.ne.jp/~Nori/ruby/dist/ClibPDF-ALPHA-20010519.tar.g ...
- 几种通过JDBC操作数据库的方法,以及返回数据的处理
1.SQL TO String :只返回一个查询结果 例如查询某条记录的总数 rs = stmt.executeQuery(replacedCommand); if (rs ! ...
- #define用法解析
#define Add(a,b) a+b; 在一般使用的时候是没有问题的,但是如果遇到如: c * Add(a,b) * d 的时候就会出现问题,代数式的本意是a+b然后去和c,d相乘,但是因为使用了 ...
- DataTable的子查询--DataTable.Select()
由于需要,在sql查询获得结果集之后,又需要对该结果再进行筛选一次,若重新从sql中查询会浪费资源,因此特地去查阅了一些资料,学会了用DataTable进行子查询. 在.Net Framework 2 ...
- Math.abs(~2018),掌握规律即可!
Math.abs(~2018) 某前端群的入门问题长姿势了,一个简单的入门问题却引发了我的思考,深深的体会到自己在学习前端技术的同时忽略遗忘了一些计算机的基础知识. 对于 JS Math对象没什么可说 ...
- HTML5新增元素
由于DIV的滥用,导致页面结构混乱,所以,与HTML4相比,HTML5主要新增了结构元素 新增的元素 1.结构元素: section 表示页面中的一个块或者章节,比如页眉.页脚,或者页面中的其它部分 ...