What is the meaning of {id:.+} in a Spring MVC requestmapping handler method?

The syntax of a path variable in a spring MVC controller requestmapping is {variable_name:regular_expression}. You can optionally omit the regular expression, which leads to what you see more often, {id}. So, for the example /index/{endpoint}/{type}/{id:.+} the variable name is id and the regular expression is .+ (see below reference to spring docs). The regular expression … Read more

SPRING REST: The request was rejected because no multipart boundary was found

The problem isn’t in your code – it’s in your request. You’re missing boundary in your multipart request. As it said in specification: The Content-Type field for multipart entities requires one parameter, “boundary”, which is used to specify the encapsulation boundary. The encapsulation boundary is defined as a line consisting entirely of two hyphen characters … Read more

Spring webflux and reading from database

One option would be to use alternative SQL clients that are fully non-blocking. Some examples include: https://github.com/mauricio/postgresql-async or https://github.com/finagle/roc. Of course, none of these drivers is officially supported by database vendors yet. Also, functionality is way much less attractive comparing to mature JDBC-based abstractions such as Hibernate or jOOQ. The alternative idea came to me … Read more

Why is my Spring 3 Validator Validating Everything on the Model?

I guess this behaviour is not covered in the documentation well. The problem is caused by the following: By default, @InitBinder-annotated method is called for each non-primitive model attribute, both incoming and outcoming (the purpose of calling it for outcoming attibutes is to allow you to register custom PropertyEditors, which are used by form tags … Read more

Why isn’t Spring running my @Scheduled method?

add “task:annotation-driven” ? <beans> <!– XMLNS, XSD declarations omitted for brevity –> <context:component-scan base-package=”com.mypackage”/> <task:annotation-driven/> <task:executor id=”executor” pool-size=”5″/> <task:scheduler id=”scheduler” pool-size=”5″/> <task:annotation-driven scheduler=”scheduler” executor=”executor”/> </beans> reference http://howtodoinjava.com/2013/04/23/4-ways-to-schedule-tasks-in-spring-3-scheduled-example/ or Spring @Configuration (non-xml configuration) for annotation-driven tasks Just add @EnableScheduling on you WebMvcConfig class @Configuration @EnableWebMvc @EnableAsync @EnableScheduling public class WebMvcConfig extends WebMvcConfigurerAdapter { /** Annotations config … Read more

How to test Spring @EventListener method?

First, As you’re using Spring Boot, the testing of these becomes pretty straightforward. This test will spin up the boot context and inject a real instance of ApplicationEventPublisher, but create a mocked instance of SomeDependency. The test publishes the desired event, and verifies that your mock was invoked as you expected. @RunWith(SpringRunner.class) @SpringBootTest public class … Read more

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration

This is caused by non-matching Spring Boot dependencies. Check your classpath to find the offending resources. You have explicitly included version 1.1.8.RELEASE, but you have also included 3 other projects. Those likely contain different Spring Boot versions, leading to this error.