Why are my Thymeleaf Path variables breaking my HTML?

Issue I have two similar controller methods that I’m using to test the @PathVariable annotation with: @RequestMapping( value = "/1", method = {RequestMethod.GET}) public String two(Model model) { model.addAttribute("category", "acategory"); model.addAttribute("subCategory", "placeholder"); return "homePage"; } @RequestMapping( path = "/{category}/{subcategory}", method

Continue reading

Axios post multipart with object

Issue Here is my spring boot endpoint to post file and object in one request @PostMapping( value = ["/add"], consumes = [ MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE ] ) fun addUser( @RequestPart("user") user: UserDTO, @RequestPart("file") file: MultipartFile, ): Long = userService.addUser(user,

Continue reading

Factory method 'jwtAccessTokenConverter' threw exception; nested exception is java.lang.IllegalArgumentException:

Issue It’s an error that comes out during spring build. I changed the difference from the existing source code to mariaDB -> mysqlDB. I wonder why this error is coming out. org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration’: Invocation of

Continue reading

Spring Boot/Gradle/Logback: bootRun fails with "Failed to instantiate [ch.qos.logback.classic.LoggerContext]": java.lang.AbstractMethodError:

Issue In a new Spring Boot application, when I gradle bootRun, I see this error: Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported exception: java.lang.AbstractMethodError: ch.qos.logback.classic.pattern.EnsureExceptionHandling.process(Lch/qos/logback/core/Context;Lch/qos/logback/core/pattern/Converter;)V at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:86) at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:28) at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:164) at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85) at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) at

Continue reading

Map Nested elements – Mapstruct

Issue I’m trying to map following source classes to target class using MapStruct. Target Classes : public class Response { private List<Customer> customer = new ArrayList<Customer>(); } public class Customer { private String customerId; private List<Product> products = new ArrayList<Product>();

Continue reading

Disable HTTP cache in WebFlux

Issue In Spring Boot MVC app I disable HTTP cache this way: WebContentInterceptor cacheInterceptor = new WebContentInterceptor(); cacheInterceptor.setCacheSeconds(0); cacheInterceptor.setUseExpiresHeader(true); cacheInterceptor.setUseCacheControlHeader(true); cacheInterceptor.setUseCacheControlNoStore(true); registry.addInterceptor(cacheInterceptor); How to do it in Spring Boot WebFlux app? Solution If you’re using Spring Boot and you’d like

Continue reading

Looking for an alternative of retryWhen which is now Deprecated

Issue I’m facing an issue with WebClient and reactor-extra. Indeed, I have the following method : public Employee getEmployee(String employeeId) { return webClient.get() .uri(FIND_EMPLOYEE_BY_ID_URL, employeeId) .retrieve() .onStatus(HttpStatus.NOT_FOUND::equals, clientResponse -> Mono.empty()) .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new MyCustomException(“Something went wrong calling getEmployeeById”))) .bodyToMono(Employee.class)

Continue reading

Return the complete response using Spring WebClient

Issue I have the following code public ClientResponse doGet(HttpServletRequest request, URI uri) { return webClient.get() .uri(uri.toASCIIString()) .headers(headers -> headers.putAll(processRequest(request)) .exchange() .block(); } But when I try to return this ClientResponse through the RestController as follows, @GetMapping @ResponseBody public ClientResponse doGet(HttpServletRequest

Continue reading

How to use WebClient to execute synchronous request?

Issue Spring documentation states that we have to switch from RestTemplate to WebClient even if we want to execute synchronous http call. For now I have following code: Mono<ResponseEntity<PdResponseDto>> responseEntityMono = webClient.post() .bodyValue(myDto) .retrieve() .toEntity(MyDto.class); responseEntityMono.subscribe(resp -> log.info(“Response is {}”,

Continue reading

Table 'DBNAME.hibernate_sequence' doesn't exist

Issue I have a SpringBoot 2.0.1.RELEASE application using spring data / jpa <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> But when I do an update in the Amazon Aurora DB, I got this error: 2018-04-13 09:20 [pool-1-thread-1] ERROR o.h.id.enhanced.TableStructure.execute(148) – could not read

Continue reading

Spring boot – Not a managed type

Issue I use Spring boot+JPA and having a problem while starting the service. Caused by: java.lang.IllegalArgumentException: Not an managed type: class com.nervytech.dialer.domain.PhoneSettings at org.hibernate.jpa.internal.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:219) at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:68) at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:65) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:145) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:89) at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:69) at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:177) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:239) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:225)

Continue reading

I have a problem with testing adding user with password encoder

Issue I have a problem when testing a method with using passwordencoder: Cannot invoke "org.springframework.security.crypto.password.PasswordEncoder.encode(java.lang.CharSequence)" because the return value of "com.store.restAPI.user.UserConfig.passwordEncoder()" is null` Thats my test class method: @ExtendWith(MockitoExtension.class) class UserServiceTest { private UserService underTest; @Mock private UserRepository userRepository; @Mock

Continue reading