Spring

【SpringBoot DB 系列】Redis 高级特性之发布订阅

柔情痞子 提交于 2021-02-10 06:01:23
【SpringBoot DB 系列】Redis 高级特性之发布订阅 通常来讲,当我们业务存在消息的业务逻辑时更多的是直接使用成熟的 rabbitmq,rocketmq,但是一些简单的业务场景中,真的有必要额外的引入一个 mq 么?本文将介绍一下 redis 的发布订阅方式,来实现简易的消息系统逻辑 <!-- more --> I. 基本使用 1. 配置 我们使用 SpringBoot 2.2.1.RELEASE 来搭建项目环境,直接在 pom.xml 中添加 redis 依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> 如果我们的 redis 是默认配置,则可以不额外添加任何配置;也可以直接在 application.yml 配置中,如下 spring: redis: host: 127.0.0.1 port: 6379 password: 2. 使用姿势 redis 的发布/订阅,主要就是利用两个命令 publish/subscribe ; 在 SpringBoot 中使用发布订阅模式比较简单,借助 RedisTemplate 可以很方便的实现 a. 消息发布

在 Spring Boot 2 中致敬 JSP

百般思念 提交于 2021-02-10 06:01:00
新冠病毒🦠还在阻挡全世界重启,但我们学习脚步不不能停滞,接下来给大家展示一个现在开发中已经不太常用的一个小知识点,希望对大家有所启发。 在平时 大家可能用 Spring Boot 2 最多就是开发 RESTful API,可能很少有人在 Spring Boot 2 中用过JSP视图,那我就来一起体验下创建一个用 JSP 视图的 Spring Boot 2 应用有多么方便。 一起来看看我们需要些什么 项目结构 咱们可以从 Spring Initializer 获取项目框架。 项目依赖 <u>pom.xml</u> <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId>

Validate LocalDate in JSON response with Spring MockMVC

我只是一个虾纸丫 提交于 2021-02-10 05:56:48
问题 I'm trying to validate a LocalDate object in a JSON result returned by a Spring MVC webservice but I can't figure out how. At the moment I always run into assertion errors like the following one: java.lang.AssertionError: JSON path "$[0].startDate" Expected: is <2017-01-01> but: was <[2017,1,1]> The important part of my test is posted below. Any ideas how to fix the test to pass? import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; public class

Spring Mapping Url to Controller and View

房东的猫 提交于 2021-02-10 05:33:49
问题 I have the standard Spring 4.x files in Netbeans 8.0.2. I added a controller, RegisterController.java in the controllers -package. I also added one model, a User , with some basic information about the user. Next I made 2 .jsp files, Registration.jsp and RegistrationSuccess.jsp . Here is my RegisterController : @Controller @RequestMapping(value="/register") public class RegisterController { @RequestMapping(method=RequestMethod.GET) public String viewRegistration(Model model){ User user = new

JAVA是否适合非科班者自学入行?石油工程专业从培训到JAVA入门自学亲身经历

眉间皱痕 提交于 2021-02-10 05:19:32
如今的我已经过了三十而立的年纪,虽然在三十岁我没有立下任何事业,相反,还在茫茫苦海中挣扎。 但是我并不是没有收获。当然,曾经在我拥有大好青春年华的时候选择了迷茫,以至于当我有所明悟的时候,却已经错过了最好的时光。 那年我二十八岁,经朋友介绍,初次接触了JAVA。当时由于年纪的原因,我报了培训班。可能是当时不够了解,就被一个特垃圾的培训机构忽悠了去,以致于到培训结束的时候,老师只教了Spring,Sturts,Herinate,以及JDBC等过时的老知识。而自己也是懵懵懂懂,一问三不知。 虽然初生牛犊不怕虎的去找工作,但不出意外,全部失利。唉,只怪自己当初选择的培训班不慎重。 于是,我静下心来,认认真真的捋了捋自己接下来的路该如何走。经过一番自我反省,我意识到,培训班没学好,那就自己去自学。 当然对于如何自学,自己从哪里找比较符合的自学资料,成了我的难题。于是我常常面试结束后,就赶紧去网上找找关于JAVA初学者如何自学的网站和资料,以及如何制定自己的自学计划。 功夫不负有心人,终于有一天,我偶尔发现了了这个网站,我迫不及待的进行了注册,果然没让我失望!!! 那么我是如何在这个网站进行自学的呢?而其他的JAVA初学者又如何自学才能有效的提高技术水平呢? 首先,自学不是一蹴而就的,是需要长时间的积累才能有所成效的。所谓冰冻三尺,非一日之寒,不积跬步,无以至千里

Mapstruct to update values without overwriting

南楼画角 提交于 2021-02-10 05:11:42
问题 Is there a way to instruct MapStruct to not overwrite values in the target? For example: public interface IMyMapper { IMyMapper INSTANCE = Mappers.getMapper(IMyMapper.class); @Mappings({ @Mapping(target = "foo", source = "source.FOO"), @Mapping(target = "bar", source = "source.BAR2"), }) void updateTargetEntity(@MappingTarget MyTarget target , MySource source); } class MyTarget { String a; String b; ... } class MySource { String a; String b; ... } Where for instance target will have a = "asdf

Spring JsonDeserializer not working for the type String

我的未来我决定 提交于 2021-02-10 04:56:11
问题 I have a requirement to strip off all the special characters and control characters from the fields of type String in any of the Objects. Deserializer was registered but never executes during the runtime for Strings . I tried adding the same as an annotation @JsonDeserialize(using = StringProcessorComponent.class) , but the same issue. It works for any other type like Date / Long . Please let me know if I am missing any. Here is my Deserializer. @JsonComponent public class

how to achieve Ldap Authentication using spring security(spring boot)

夙愿已清 提交于 2021-02-10 04:15:31
问题 I have following code with me I am trying to achieve ldap Authentication but i think it is not happening. My Security Configuration @EnableWebSecurity @Configuration @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class Config extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().and().authorizeRequests().antMatchers("/*") .permitAll().anyRequest().authenticated().and().csrf() .disable().httpBasic().and().csrf(

how to achieve Ldap Authentication using spring security(spring boot)

风流意气都作罢 提交于 2021-02-10 04:15:27
问题 I have following code with me I am trying to achieve ldap Authentication but i think it is not happening. My Security Configuration @EnableWebSecurity @Configuration @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class Config extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().and().authorizeRequests().antMatchers("/*") .permitAll().anyRequest().authenticated().and().csrf() .disable().httpBasic().and().csrf(

how to achieve Ldap Authentication using spring security(spring boot)

≯℡__Kan透↙ 提交于 2021-02-10 04:14:57
问题 I have following code with me I am trying to achieve ldap Authentication but i think it is not happening. My Security Configuration @EnableWebSecurity @Configuration @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class Config extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().and().authorizeRequests().antMatchers("/*") .permitAll().anyRequest().authenticated().and().csrf() .disable().httpBasic().and().csrf(