Spring

Springboot 热部署的两种方式

流过昼夜 提交于 2021-02-09 19:03:11
https://yiqiwuliao.com/post/spring/springbootre-bu-shu#toc_3 记得修改下面参数 1. build project auto..... 2. shift + alt + ctrl + / -> regis.... 3. 使用下面命令debug运行 mvn spring-boot:run -Drun.jvmArguments= " -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 " run -> Edit Configura.... -> remote 拓展:基于Tomcat的远程debug vim bin/catalina.sh 在第一行添加 CATALINA_OPTS="-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8899" 使用IDEA 创建一个remote 填写ip和端口链接即可进行远程debug 来源: oschina 链接: https://my.oschina.net/u/4315677/blog/3787656

Spring Boot进阶系列四

試著忘記壹切 提交于 2021-02-09 15:34:12
这边文章主要实战如何使用Mybatis以及整合Redis缓存,数据第一次读取从数据库,后续的访问则从缓存中读取数据。 1.0 Mybatis MyBatis 是支持定制化 SQL、存储过程以及高级映射的优秀的持久层框架。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以对配置和原生Map使用简单的 XML 或注解,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。 MyBatis并不是一套完整的ORM数据库连接框架,目前大多数互联网公司首选的数据库连接方式,不会对应用程序或者数据库的现有设计强加任何影响。 SQL写在xml里,便于统一管理和优化。解除SQL与程序代码的耦合:通过提供DAL层,将业务逻辑和数据访问逻辑分离,使系统的设计更清晰,更易维护,更易单元测试。SQL和代码的分离,提高了可维护性。 它的优点也正是缺点,编写SQL语句时工作量很大,尤其是字段多、关联表多时,更是如此。 SQL语句依赖于数据库,导致数据库移植性差,不能更换数据库。 1.1使用 MyBatis 官方提供的 Spring Boot 整合包实现。 1.1.1. pom.xml里面添加mybatis jar包。 <!-- springboot,mybatis 整合包 --> <

SpringBoot热部署的两种方式

落爺英雄遲暮 提交于 2021-02-09 15:33:05
SpringBoot热部署方式一共有两种,分别使用两种不同的依赖   SpringBoot 1.3后才拥有SpringBoot devtools热部署   ①:spring-boot-devtools ②:Spring Loaded   方式一:     在项目的pom文件中添加依赖: 1 <!--热部署jar--> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-devtools</artifactId> 5 </dependency>     然后:使用 shift+ctrl+alt+"/" (IDEA中的快捷键) 选择"Registry" 然后勾选 compiler.automake.allow.when.app.running   方式二:     在项目中添加如下代码 <build> <plugins> <plugin> <!-- springBoot编译插件--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <!-- spring热部署 --> <!--

带你认识互联网架构的演变过程

六眼飞鱼酱① 提交于 2021-02-09 13:53:04
单体架构(all in one) 所有模块都在一起,技术也不分层。 在单机上部署所有的应用程序和软件。 所有的代码都写在JSP里面,所有代码都写在一起,这种方式称为all in one。 特点: 1.不具备代码的可维护性。 2.容错性差。(容错性是指软件检测应用程序所运行的软件和硬件中发生的错误并从错误中恢复的能力,可以从系统的可靠性,可用性,可测性等几个方面衡量) 因为所有代码都写在JSP页面里,当因为用户或某些原因发生异常时:用户可以直接看到异常错误信息;异常会导致服务器宕机。 单体地狱: 只需一个应用,将所有功能部署在一起,以减少部署节点和成本。 解决方案 1.分层开发:解决单体架构容错性差的问题,同时提高了代码的维护性。 2.MVC架构(Web应用程序的设计模式) 3.服务器的部署分离。 特点: 1.MVC分层开发:解决容错性问题。 2.数据库和项目部署分离。 <font color=red>问题</font>: 1.高并发:随着用户访问量的持续增加,单台服务器无法满足用户访问需求。 解决方案: 1.集群 集群操作可能遇到的问题 高可用 高可用HA(High Availability)是分布式系统架构设计中必须考虑的因素之一,它通常是指,通过设计减少系统不能提供服务的时间。假设系统一直能够提供服务,我们说系统的可用性是100%。 如何保证高可用:避免单点。 高并发 高并发

Does RestTemplate automatically release connection?

百般思念 提交于 2021-02-09 12:52:17
问题 I am shifting my REST client module from HttpClient.executeMethod(method) to RestTemplate.postForLocation(uri, obj) . With the HttpClient, I would explicitly release the connection of the method: deleteMethod.releaseConnection(); I cannot find anything equivalent within the Spring RestTemplate. Does it automatically release connections? Another way to ask would be, I suppose, is it safe to not do anything after calling the RestTemplate.postForLocation ? 回答1: One of the goals of spring

Does RestTemplate automatically release connection?

江枫思渺然 提交于 2021-02-09 12:45:03
问题 I am shifting my REST client module from HttpClient.executeMethod(method) to RestTemplate.postForLocation(uri, obj) . With the HttpClient, I would explicitly release the connection of the method: deleteMethod.releaseConnection(); I cannot find anything equivalent within the Spring RestTemplate. Does it automatically release connections? Another way to ask would be, I suppose, is it safe to not do anything after calling the RestTemplate.postForLocation ? 回答1: One of the goals of spring

(转)美团面试题整理

心已入冬 提交于 2021-02-09 12:01:03
背景:最近美团在招聘,打算好好准备准备简历,然后投递一波。 美团点评 社招 一面(3.6中午)结果通过 美女面试官 1 HashMap的put怎么实现,如何解决hash冲突。 调用putval,计算相应hash码,然后初始化(默认64的capacity)或调用resize函数调整大小,判断bucket是否有值,若没有在数组初始化改值。若有则以拉链法(链表的形式)解决hash冲突,这里和ThreadLocalMap不一样,ThreadLocalMap使用的是线性探测法,接着将相应节点加入链表头部。如果超过8个元素会进化为RBtree,防止hash攻击。 RBtree是怎样的数据结构,有什么性质? 二叉树,有序的,四种性质。从而推得路径最长2n,最短n。复杂度为log2N.(此处省略n多话,感兴趣的同学请自行Google) RBtree什么时候会变色? 旋转时,共有四种旋转方式。一般是为了保持平衡,如左边太长,右边太短这样。(打哈哈过去,具体记不清了) hashmap什么时候会调整大小? 根据负载因子来搞事,默认为0.75。 什么是负载因子? 根据capacity来,举个例子,当capacity为100时,如果HashMap的ele的数量到了75就会resize,resize后的大小为原来的2倍,这样可以直接使用位运算得到原来的元素新的hash值。 扩容存在什么问题? (楞了一会

Spring first request very slow

孤街浪徒 提交于 2021-02-09 11:48:36
问题 I have application in Spring Boot. After initialization of Spring Boot with embeded tomcat, the first response is very slow. How can I fix it? Has spring boot any warmup command/mode? I am thinking too about connection with database and I am wondering about connection database, probably spring connects with Postgres during first request. 回答1: You could either use ApplicationRunner or CommandlineRunner to run something on startup: https://docs.spring.io/spring-boot/docs/current/reference

springMVC异常统一处理

♀尐吖头ヾ 提交于 2021-02-09 11:36:28
SpringMVC 提供的异常处理主要有两种方式,一种是直接实现自己的HandlerExceptionResolver,另一种是使用注解的方式实现一个专门用于处理异 常的Controller——ExceptionHandler。前者当发生异常时,页面会跳到指定的错误页面,后者同样,只是后者会在每个 controller中都需要加入重复的代码。如何进行简单地统一配置异常,使得发生普通错误指定到固定的页面,ajax发生错直接通过js获取,展现给 用户,变得非常重要。下面先介绍下2种异常处理方式,同时,结合现有的代码,让其支持ajax方式,实现spring MVC web系统的异常统一处理。 1、实现自己的HandlerExceptionResolver,HandlerExceptionResolver是一个接 口,springMVC本身已经对其有了一个自身的实现——DefaultExceptionResolver,该解析器只是对其中的一些比较典型的异常 进行了拦截处理 。 Java代码 import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet

JPA use Spring Data Specification for delete and update

扶醉桌前 提交于 2021-02-09 11:33:57
问题 JPA Specification is powerful in order to build WHERE clauses. But, it seems to be defined only for SELECT (with findAll method). Is it possible to have the same behavior with DELETE and UPDATE? So that, it would be possible to avoid selecting scope before deleting or updating it. Thx 回答1: You can use CriteriaUpdate and CriteriaDelete. Im building my specification from a RSQL query here but it can be done in a lot of other ways as well (see https://www.programcreek.com/java-api-examples/index