Spring

Spring Transaction Management with Hibernate and MySQL, Global and Local

孤街浪徒 提交于 2021-02-20 19:18:08
问题 Im working on developing a webapplication with MySQL Server 5.1, Spring 3.0.5 and Hibernate 3.6. I use Springs Transaction Management. Im a newbie, so please be patient with me if I ask a question which is easy to answer. :-) 1) I read about global (xa) and local transactions. Is it correct, that global transactions mean transactions, which execute dataoperations on different resources (like different databases). And that local transactions execute dataoperations on only one resource

Spring-JPA中关于Entity继承的问题(上)

僤鯓⒐⒋嵵緔 提交于 2021-02-20 17:12:59
参考资料: https://developer.aliyun.com/article/312873 org.hibernate.WrongClassException:Object with [id=11] was not of the specified subclass: xxxx.entity(loaded object was of wrong class ... 这个错误其实是说,在构建当前的Entity1列表(LIST)的时候,发现该Entity所共用对象的另一个Entity2中,已经存在了id=11的对象,并且Entity1和Entity2的id=11的对象在结构上是不一样的,无法覆盖。 看到这个错误是不是有点蒙,像是在听天书的感觉?其实,这个Exception的本质是和JPA中hibernate的继承映射有关。 当前笔者的项目中,定义了BaseEntity,其中包含了code(编码),name(名称),elementcode(要素的tag)这些通用属性。然后,分别定义了Entity1和Entity2,且都集成自BaseEntity。Entity1和Entity2的的elementcode返回的内容不一样。举例子来描述的话,就相当于两组不同的字典要素,一个是桌子(Entity1,elementcode=桌子),一个是椅子(Entity2,elementcode=椅子)

基于zookeeper分布式锁

早过忘川 提交于 2021-02-20 16:48:46
最近项目中新上线了抢优惠券功能,虽然用户不多但是,如何防止超发呢?单体应用情况下只需要在抢券方法前用synchronized修饰即可,但是目前大部分项目都是分布式微服务架构,所以就需要加分布式锁。项目用的SpringMVC+dubbo,注册中心使用的zookeeper,所以就选用的基于zookeeper的分布式锁。 原生的zookeeper分布式锁写起来比较复杂,使用zookeeper的Curator框架轻松实现,代码实现: pom文件 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-recipes</artifactId> <version>4.0.1</version> </dependency> Spring集成 <!-- 重连策略 --> <bean id="retryPolicy" class="org.apache.curator.retry.ExponentialBackoffRetry"> <!-- 间隔时间基数 -->

Log values of query parameters in Spring Data R2DBC?

廉价感情. 提交于 2021-02-20 16:15:25
问题 In Spring Data R2DBC I can log SQL queries by using logging.level.org.springframework.data.r2dbc=DEBUG in the application.properties . However, this doesn't log the actual values that are bound as query parameters. How can I log the actual values of query parameters in Spring Data R2DBC? 回答1: This worked for me : logging: level: io.r2dbc.postgresql.QUERY: DEBUG # for queries io.r2dbc.postgresql.PARAM: DEBUG # for parameters I found it here 回答2: If you happen to use MySQL, you can get a low

Eureka 集群高可用配置.

烂漫一生 提交于 2021-02-20 15:16:09
SERVER:1 server: port: 1111 eureka: instance: hostname: ${spring.cloud.client.ip - address} instance - id: ${eureka.instance.hostname}:${server.port} preferIpAddress: true #指定通过IP注册,一般服务集群时配置,需要ip-address参数一起设置(保证hostName和ip-address一样),以免eureka管理页面出现不可用分片提示信息(unavailable- replicas),服务的注册默认是通过hostName注册的,当判断注册的hostName和服务 ip - address: ${EUREKA_IP:${eureka.instance.hostname}} #强制指定eureka的ip地址 client: service - url: defaultZone: http: // ${eureka.instance.hostname}:1112/eureka/ fetch-registry: true #集群时需要强制手动指定,fetch-registry、register-with- eureka都需要设置为true register -with-eureka: true

Spring shutdown event that fires immediately before ApplicationContext is destroyed?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-20 14:14:34
问题 I am looking for an interceptor or a trigger to know that, all the context beans are destroyed and the applicationcontext instance is about to destroy itself. So I can do one process at the end of the application lifetime. There is this event type ContextClosedEvent, which is close to the thing that I wanna do but, it throws the event after destruction of beans. I thing it comes with the close() method of the applicationcontext. So it doesn't fit to my need Any ideas? Regards Ali 回答1: You can

Spring shutdown event that fires immediately before ApplicationContext is destroyed?

故事扮演 提交于 2021-02-20 14:12:38
问题 I am looking for an interceptor or a trigger to know that, all the context beans are destroyed and the applicationcontext instance is about to destroy itself. So I can do one process at the end of the application lifetime. There is this event type ContextClosedEvent, which is close to the thing that I wanna do but, it throws the event after destruction of beans. I thing it comes with the close() method of the applicationcontext. So it doesn't fit to my need Any ideas? Regards Ali 回答1: You can

Spring shutdown event that fires immediately before ApplicationContext is destroyed?

不想你离开。 提交于 2021-02-20 14:03:33
问题 I am looking for an interceptor or a trigger to know that, all the context beans are destroyed and the applicationcontext instance is about to destroy itself. So I can do one process at the end of the application lifetime. There is this event type ContextClosedEvent, which is close to the thing that I wanna do but, it throws the event after destruction of beans. I thing it comes with the close() method of the applicationcontext. So it doesn't fit to my need Any ideas? Regards Ali 回答1: You can

全网最新、最全面蚂蚁金服面经分享:简历模板/面试题库/Java核心技术笔记

我的梦境 提交于 2021-02-20 13:41:35
前言 前段时间,蚂蚁金服的热度可不小,互联网圈人人都在讨论它上市的事情,实际上蚂蚁金服上市是迟早的事情。这一下,蚂蚁的员工含金量上升了不少,那我之前蚂蚁提前批这波面经,也是时候分享了。 这次面试,可以说是一波三折,波涛汹涌了,原本我是一个挺自信的人的,所以在面试前我算是处于一个斗志昂扬的状态,奈何在经历一面二面意志力被消磨了不少,虽然三面准备充足,但整体下来对自己表现不满意,所以以为是没戏了,没想到意外接来了HR面的通知,于是就这么意外的拿到了offer。 下面就对这次蚂蚁金服的面试体验进行一个分享,由于面试题比较多,所以只挑选了一些有针对性的核心题放在这里解析,如果你需要完整pdf版,只需要添加小助理vx:mxzFAFAFA即可!! 蚂蚁金服意外的第一面 1、讲一讲ArrayList和LinkedList区别? ArrayList 是一个可改变大小的数组。当更多的元素加入到ArrayList中时,其大小将会动态地增长。内部的元素可以直接通过get与set方法进行访问,因为ArrayList本质上就是一个数组, LinkedList 是一个双链表,在添加和删除元素时具有比ArrayList更好的性能.但在get与set方面弱于ArrayList。 当然,这些对比都是指数据量很大或者操作很频繁的情况下的对比,如果数据和运算量很小,那么对比将失去意义。 2、什么情况会造成内存泄漏?

Using annotation @Sql, is it possible to execute scripts in Class level before Method level?

流过昼夜 提交于 2021-02-20 13:31:12
问题 I want to execute two scripts before every test method, but i also want to define some scripts to execute before specific methods. Using Spring framework and @Sql annotations, is it possible? @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/WEB-INF/application-context.xml") @DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD) @Sql({ "/database/drop_schema.sql", "/database/create_schema.sql" }) public class CentralServiceTestCase { // I want to run "drop_schema.sql",