Cloud-oriented Life

Cloud Native Technology Improves Lives

appraisal

Appraisal integrates with bundler and rake to test your library against different versions of dependencies in repeatable scenarios called “appraisals.” Appraisal is designed to make it easy to check for regressions in your library without interfering with day-to-day development using Bundler.

Read more »

puma_worker_killer

If you have a memory leak in your code, finding and plugging it can be a herculean effort. Instead what if you just killed your processes when they got to be too large? The Puma Worker Killer does just that. Similar to Unicorn Worker Killer but for the Puma web server.

Read more »

asdf and Flutter Plugin

asdf is a single CLI tool for managing multiple runtime versions. It extend with a simple plugin system to install your favourite language: Dart, Elixir, Flutter, Golang (Go), Java, Node.js, Python, Ruby …

This article is about how to use asdf and Flutter plugin to install multiple Flutter versions on macOS with the Homebrew package manager.

Read more »

EasyExcel

EasyExcel rewrote Apache POI’s analysis of version 07 of Excel. A 3M excel using POI sax analysis still requires about 100M of memory. Switching to easyexcel can be reduced to a few M, and no amount of memory overflow will occur in the larger excel; version 03 depends on The sax mode of POI is encapsulated in the upper layer for model conversion, which makes users more simple and convenient.

Read more »

Automatic restart Spring Boot application

With the spring-boot-devtools module, your application will restart every time files on the classpath change. If IntelliJ IDEA is configured to continuously compile changed files, you can set a trigger file. In this case your application will restart only after you modify the trigger file. For more information, see Automatic Restart Developing with Spring Boot - https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools.restart.

Read more »

Spring Boot Test

FAQs

No qualifying bean of type ‘org.springframework.boot.test.web.client.TestRestTemplate’ available

1
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.test.web.client.TestRestTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

TestRestTemplate is only auto-configured when @SpringBootTest has been configured with a webEnvironment that means it starts the web container and listens for HTTP requests. For example:

Note the use of webEnvironment=RANDOM_PORT to start the server with a random port (useful to avoid conflicts in test environments)

1
2
3
4
5
6
7
8
9
10
11
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class DemoServiceTest {

@Autowired
private DemoService demoService;

@Test
public void testCreate() {
demoService.Create();
}
}

References

[1] Getting Started | Testing the Web Layer - https://spring.io/guides/gs/testing-web/

Spring Boot Validation

Usages

UUID Validataion

Define a UUID Validataion.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.Pattern;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Pattern(regexp="^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", message = "Not a valid UUIDPattern")
@Retention(RUNTIME)
@Target({FIELD, METHOD, PARAMETER})
@Constraint(validatedBy = {})
@Documented
public @interface UUIDPattern {
String message() default "{invalid.uuid}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}

Example

1
2
3
4
5
6
public class User {
@Id
@GeneratedValue
@UUIDPattern
protected UUID id;
}

java - Is there a uuid validator annotation? - Stack Overflow - https://stackoverflow.com/questions/37320870/is-there-a-uuid-validator-annotation

Java validator for UUIDs - https://gist.github.com/mindhaq/ffc3378a271cb7e91b3819ff1abb675c

FAQs

HV000030: No validator could be found for constraint ‘javax.validation.constraints.Pattern’ validating type ‘java.util.UUID’.

As stated in problem, to solve this error you MUST use correct annotations. In above problem, @Pattern annotation must be applied on any String field only.

TODO.

References

Validation with Spring Boot - the Complete Guide - Reflectoring - https://reflectoring.io/bean-validation-with-spring-boot/

[1] Validation in Spring Boot | Baeldung - https://www.baeldung.com/spring-boot-bean-validation

0%