天道酬勤,学无止境

spring-boot

Can't create aspect in Spring Boot

I just want to achieve one simple thing - to create logging aspect, which should hook on every method to be able print arguments. The aspect looks like as following: @Aspect @Component @Slf4j public class MyLogger { public MyLogger () {} @AfterReturning("execution(* my.package..*.*(..))") public void logMethodAccessAfter(JoinPoint joinPoint) { System.out.println("***** Completed: " + joinPoint.getSignature().getName() + " *****"); } @Before("execution(* my.package..*.*(..))") public void logMethodAccessBefore(JoinPoint joinPoint) { System.out.println("***** Starting: " + joinPoint.getSignature

2022-01-19 01:37:48    分类:问答    spring   spring-boot   javafx   spring-aop

Deserialize duplicate keys to list using Jackson

I'm trying to deserialize json into object. However, the json has duplicate keys. I cannot change the json and I would like to use Jackson to change duplicate keys to a list. Here is an example of the json I retrieve: { "myObject": { "foo": "bar1", "foo": "bar2" } } And here is what I would like after deserialization: { "myObject": { "foo": ["bar1","bar2"] } } I created my class like so: public class MyObject { private List<String> foo; // constructor, getter and setter } I tried to use DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY from objectMapper but all it does is taking the last key

2022-01-19 01:06:59    分类:问答    java   json   spring-boot   jackson

Load data only from test/resources while testing with Spring Boot

I have an Spring Boot application integrated with Hibernate for the database persistence. I have two different data.sql files: One in src/main/resources for database initialization One in src/test/resources for testing purposes While testing, both of them are loaded before any test class. However, I only want to load the test/resources one, leaving the main/resources only and solely for app initialization. How can I do that? Thanks.

2022-01-19 00:53:33    分类:问答    java   spring   hibernate   spring-boot

set an annotation attribute from an environment variable?

I'm trying to set an annotation value from an environment variable: @Configuration @ComponentScan @EnableAutoConfiguration @EnableScheduling class Application { @Scheduled(cron = "${DB_CRON}") def void schedule() { ... } public static void main(String... args) { SpringApplication.run(Application, args) } ... } However, I get the following compile time error: Attribute 'cron' should have type 'java.lang.String'; but found type 'java.lang.Object' in @org.springframework.scheduling.annotation.Scheduled Is it possible to set the annotation this way, or do I need to use some other technique such as

2022-01-18 23:26:29    分类:问答    spring   groovy   spring-boot

How to configure resource id in resource server using oauth2 security

I am trying to create Authorization server and resource server. When tried to get access token from Authorization server its working and getting access token with following details. { "access_token": "5ffbc2d7-2a27-4f08-921f-f7de2410b5f5", "token_type": "bearer", "refresh_token": "d0fb85b3-52e0-45e0-84dc-ed38d55176a6", "expires_in": 599, "scope": "READ", "authorities": [ { "authority": "delete_profile" }, { "authority": "update_profile" }, { "authority": "read_profile" }, { "authority": "create_profile" }, { "authority": "ROLE_admin" } ], "resource_ids": [ "RESOURCE_ID1" ] } with the access

2022-01-18 23:24:16    分类:问答    spring   spring-boot   oauth-2.0   spring-security-oauth2   spring-security-rest

How do I load HashMap and ModelandView object values using Thymeleaf in a Spring Boot application?

I am unable to load the input and instance values in the browser from the HTML file using Thymeleaf for a Spring-boot application. Below is code snippet from Controller java file. @RequestMapping(value = "/x") public String launch(@RequestParam("inputFile") String inputFile, @RequestParam("instance") int instance) { ... ModelAndView mav = new ModelAndView(); Map<String, String> parameters = new HashMap<>(); parameters.put("inputFile", inputFile); parameters.put("instance", Integer.toString(instance)); mav.addObject("parameters", parameters); mav.setViewName("welcome"); return "welcome"; } Here

2022-01-18 23:19:12    分类:问答    html   spring-boot   model-view-controller   thymeleaf

Primefaces FileUpload is not working with PrettyFaces and Spring Boot

I am using Spring Boot 1.5.2.RELEASE with JSF 2.2.14 and Primefaces 6.1 and PrettyFaces 3.4.1.Final. My pom file is as follows: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>myapp</artifactId> <version>1</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId>

2022-01-18 22:17:57    分类:问答    spring-boot   file-upload   primefaces   jsf-2   prettyfaces

Spring Boot locking code to get an unique id

I wrote a controller that must return an unique String. The requirement is that two calling of this controller never return the same String, even after years and even if the code will scale to more VMs. My question is if the following code is correct to achieve to declared purpose, or if you have any hint. Controller: @RestController public class UtilityController { @Autowired UtilityServices utilityServices; @GetMapping("/uniqueIdentifier") @ResponseBody public String uniqueIdentifier() { return utilityServices.getUniqueIdentifier(); } Service: @Service public class UtilityServices {

2022-01-18 21:27:27    分类:问答    spring-boot

Spring Boot/Thymeleaf Unit Test: Model attribute does not exist

I have made a view with a form where the user can enter a value for inputTemp and the input is saved in an attribute in the Controller. View: <!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head th:include="fragments/template :: head"></head> <head> <title>Smart CV</title> </head> <body> <nav th:replace="fragments/template :: header"></nav> <div class="container"> <div class="hero-unit"> <h1>Invoerscherm</h1> </div> </div> <form action="#" th:action="@{/invoer}" th:object="${invoerscherm}" method="post"> <td><input type="text" id="inputTemp" name="inputTemp" th:value="${inputTemp}"

2022-01-18 20:33:40    分类:问答    java   spring   unit-testing   spring-boot   thymeleaf

Can spring boot controller receive plain/text?

I am trying to process a POST request with body of plain text (utf-8) but it seems that spring does not like the plain text nature of the call. Could it be that it is not supported - or otherwise, am I coding it wrong? @RestController @RequestMapping(path = "/abc", method = RequestMethod.POST) public class NlpController { @PostMapping(path= "/def", consumes = "text/plain; charset: utf-8", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> doSomething(@RequestBody String bodyText) { ... return ResponseEntity.ok().body(responseObject); } } Respond is: Resolved [org

2022-01-18 17:48:20    分类:问答    java   spring   rest   spring-boot