Spring

BindException thrown instead of MethodArgumentNotValidException in REST application

可紊 提交于 2021-02-17 21:44:50
问题 I have a simple Spring Rest Controller with some validation. My understanding is that validation failures would throw a MethodArgumentNotValidException. However, my code throws a BindException instead. In debug messages, I also see the app returning a null ModelAndView. Why would a Rest Controller throw BindException or return a null ModelAndView? Note: I am testing my web application using curl and making an HTTP POST curl -X POST http://localhost:8080/tasks I am intentionally omitting the

Spring JPA REST sort by nested property

五迷三道 提交于 2021-02-17 21:43:35
问题 I have entity Market and Event . Market entity has a column: @ManyToOne(fetch = FetchType.EAGER) private Event event; Next I have a repository: public interface MarketRepository extends PagingAndSortingRepository<Market, Long> { } and a projection: @Projection(name="expanded", types={Market.class}) public interface ExpandedMarket { public String getName(); public Event getEvent(); } using REST query /api/markets?projection=expanded&sort=name,asc I get successfully the list of markets with

WebSocket Stomp over SockJS - http custom headers

这一生的挚爱 提交于 2021-02-17 21:25:33
问题 I'm using stomp.js over SockJS in my javascript client. I'm connecting to websocket using stompClient.connect({}, function (frame) { stomp over sockJS connection has 2 http requests: request to /info http upgrade request the client sends all cookies. I would like to also send custom headers (e.g. XSRF header) but didn't find a way to do that. Will appreciate any help. 回答1: @Rohitdev So basically you can't send any HTTP headers using stompClient, because STOMP is layer over websockets, and

常问的22道Java面试题,值得收藏【文末送书】

微笑、不失礼 提交于 2021-02-17 20:41:58
作者:爱茹一婉年 原文: https : //blog.csdn.net/qq_21924011/article/details/80399836 1)集合类:List和Set比较,各自的子类比较(ArrayList,Vector,LinkedList;HashSet,TreeSet) List:元素是有顺序的,元素可以重复因为每个元素有自己的角标(索引) |-- ArrayList:底层是数组结构,特点是:查询很快,增删稍微慢点,线程不同步:A线程将元素放在索引0位置,CPU调度线程A停止,B运行,也将元素放在索引0位置,当A和B同时运行的时候Size就编程了2. |-- LinkedList:底层使用的是链表数据结构,特点是:增删很快,查询慢。线程不安全,线程安全问题是由多个线程同时写或同时读写同一个资源造成的。 |--Vector:底层是数组数据结构,线程同步,Vector的方法前面加了synchronized关键字,被ArrayList代替了,现在用的只有他的枚举。 Set:元素是无序的,且不可以重复(存入和取出的顺序不一定一致),线程不同步。set底层是使用Map实现的,故可以通过ConcurrentHashMap的方式变通实现线程安全的Set。 |--HashSet:底层是哈希表数据结构。根据hashCode和equals方法来确定元素的唯一性。

Custom WebSecurityConfigurerAdapter

陌路散爱 提交于 2021-02-17 20:27:20
问题 I have this problem implementing a custom login authentication using SpringBoot and SpringBoot-Security. I made a Bitbucket repository as reference for this thread (within CustomSecuringWeb branch). Before anything else, most of the comments here follows the Securing a Web Application tutorial. The thing is, I was curious as how could the authentication data is now from the database instead of just memory data (which is very common in production line applications). Throughout the process I

Thymeleaf + spring dynamic replace

試著忘記壹切 提交于 2021-02-17 19:35:27
问题 Is it possible to create a dynamic replace in Thymeleaf? I have the following controller: @Controller public class LoginController { @RequestMapping("/login") public String getLogin(Model model){ model.addAttribute("template","login"); return "index"; } } And the following view: <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" > <head></head> <body> <div th:replace="fragments/${template} :: ${template}"></div> </body> </html> And i'm getting the following error: Error resolving

Thymeleaf + spring dynamic replace

无人久伴 提交于 2021-02-17 19:35:18
问题 Is it possible to create a dynamic replace in Thymeleaf? I have the following controller: @Controller public class LoginController { @RequestMapping("/login") public String getLogin(Model model){ model.addAttribute("template","login"); return "index"; } } And the following view: <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" > <head></head> <body> <div th:replace="fragments/${template} :: ${template}"></div> </body> </html> And i'm getting the following error: Error resolving

Spring configuration properties metadata json for nested list of Objects

我只是一个虾纸丫 提交于 2021-02-17 19:34:06
问题 How does one configure spring configuration metadata json for nested list of objects? Scenario @ConfigurationProperties(prefix = "custom-config") public class ConfigProperties { private boolean booleanProperty; private List<NestedObject> listProperty = new LinkedList<>(); //getters and setters } public class NestedObject { private String stringProperty; private boolean booleanProperty; //getters and setters } This is what was auto generated in the metadata json { "groups": [{ "name": "custom

事务特性,事务的隔离级别,并发事务可能出现的问题,spring事务 数据库锁

六眼飞鱼酱① 提交于 2021-02-17 18:48:25
1.0 事务特性(ACID) Atomicity:原子性,一个事务不可以被拆分 Consistency:一致性,在事务执行前数据库的数据处于正确的状态,而事务执行完成后数据库的数据还是处于正确的状态,即数据完整性约束没有被破坏;比如我们做银行转账的相关业务,A转账给B,要求A转的钱B一定要收到。如果A转了钱而B没有收到,那么数据库数据的一致性就得不到保障,在做高并发业务时要注意合理的设计。 Isolation:隔离性,并发事务执行之间无影响,在一个事务内部的操作对其他事务是不产生影响,这需要事务隔离级别来指定隔离性; Durability:持久性,事务一旦执行成功,它对数据库的数据的改变必须是永久的,不会因各种异常导致数据不一致或丢失。 1.1 事务的隔离级别   READ_UNCOMMITTED 会出现脏读、不可重复读、幻读 ( 隔离级别最低,并发性能高 )   READ_COMMITTED 会出现不可重复读、幻读问题(锁定正在读取的行)   REPEATABLE_READ 会出幻读(锁定所读取的所有行)   SERIALIZABLE 保证所有的情况不会发生(锁表) 大多数数据库的默认隔离级别为: Read Commited,如Sql Server , Oracle . 少数数据库默认的隔离级别为Repeatable Read, 如 MySQL InnoDB存储引擎 1

国产微服务网关-Soul(真香)

旧街凉风 提交于 2021-02-17 13:13:14
What is the Soul? 一个异步的,高性能的,跨语言的,响应式的API网关。我希望能够有一样东西像灵魂一样,保护您的微服务。参考了Kong,Spring-Cloud-Gateway等优秀的网关后,站在巨人的肩膀上,Soul由此诞生! 是不是很吊的一句话,站在巨人身上那么这些巨人也就变成了矮子。 整体架构如下图所示: 是不是很炫反正我是没看懂 部署单机版 操作在windows环境 安装SoulAdmin souladmin:控制台,负责维护网关的 元数据 、配置等等,并提供给 SoulBootstrap 网关服务 读取。 在mysql数据库中执行下面图中sql,12张表 在浏览器输入 https://yu199195.github.io/jar/soul-admin.jar 回车下载即可,yml文件复制一份在外部启动,用自己的数据库 启动命令:java -jar soul-admin.jar --spring.config.location=xxxxx\application-local.yml 启动成功后 通过日志看到 Soul Admin 启动在 9095 端口。使用浏览器,访问 http://127.0.0.1:9095/ 地址,进入登录页,账号密码分别是:admin 和123456 安装SoulBootstrap SoulBootstrap:网关服务,负责启动网关