Spring HandlerInterceptor vs Servlet Filters

The org.springframework.web.servlet.HanderInterceptor Interface JavaDoc itself has a two paragraphs that discuss this question: HandlerInterceptor is basically similar to a Servlet 2.3 Filter, but in contrast to the latter it just allows custom pre-processing with the option of prohibiting the execution of the handler itself, and custom post-processing. Filters are more powerful, for example they allow … Read more

Why did Spring framework deprecate the use of Guava cache?

Spring project decided to endorse a switch to Caffeine cache. Caffeine supersedes the caching support in the Google Guava library with an actively maintained Java 8+ version in standalone form. You can find the relevant issue with the decision on Spring’s tracker here: https://jira.spring.io/browse/SPR-13797 The relevant commit in spring framework github repo is: https://github.com/spring-projects/spring-framework/commit/2bf9bc312ed1721b5978f88861c29cffc9ea407c

Spring and hibernate: No Session found for current thread

You annotated your Dao class with @Transactional, but not your service class. The line: Visitor storedVisitor = (Visitor) sessionFactory.getCurrentSession().get(Visitor.class, visitorDetails.getTfscNumber(), LockMode.NONE); requires you to be in a transaction. You can fix this by adding the @Transactional annotation to your ProfileService class, or just the registerVisitor() method.

Send datas from html to controller in Thymeleaf?

You can find an example in http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#creating-a-form. As the tutorial suggests, you need to use th:object, th:action and th:field to create a form in Thymeleaf. It looks like this: Controller: @RequestMapping(value = “/showForm”, method=RequestMethod.GET) public String showForm(Model model) { Foo foo = new Foo(); foo.setBar(“bar”); model.addAttribute(“foo”, foo); … } @RequestMapping(value = “/processForm”, method=RequestMethod.POST) public String … Read more

How to test a spring controller method by using MockMvc?

You can use your applications dispatcher servlet xml using the following annoations. The following example is hitting a controller with the path /mysessiontest setting some session attributes and expecting a certain view to be returned: import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; … Read more

Enable HAL serialization in Spring Boot for custom controller method

There’s a lot of aspects here: I doubt that the collection resource at /transactions really returns an individual transaction as you described. Those representations are returned for item resources. If TransactionRepository already is a PageableAndSortingRepository the collection resource can be tweaked by expanding the URI template exposed in the API root for the link named … Read more

spring boot war without tomcat embedded

Following the Hint from M. Deinum I excluded the tomcat-depedency. With the following pom.xml (relevant snippet) a maven clean package has the result I want to get. … <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!– Add tomcat only if I want … Read more