Configure spring boot to redirect 404 to a single page app [duplicate]

This is the full Spring Boot 2.0 example: @Configuration public class WebApplicationConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController(“/notFound”).setViewName(“forward:/index.html”); } @Bean public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() { return container -> { container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, “/notFound”)); }; } }

How to implement @RequestMapping custom properties

I’ve created solution based on referenced spring-mvc-31-demo This solution can be used to map only single RequestCondition as of now. I’ve created two Issues to notify, this should be changed: https://github.com/rstoyanchev/spring-mvc-31-demo/issues/5 https://jira.springsource.org/browse/SPR-9350 This solution uses custom @RequestCondition feature of Spring 3.1.1.RELEASE platform USAGE Example 1: @Controller @SubdomainMapping(value = “subdomain”, tld = “.mydomain.com”) class MyController1 { … Read more

Using both Thymeleaf and JSP

According to this post on the Thymeleaf forum, you have two solutions. First solution : Remove the suffix property in your bean declaration (<property name=”suffix” value=”.html” /> and <property name=”suffix” value=”.jsp” />) and pass the suffix in the return value of your controllers, e.g. : @RequestMapping(“/view1”) public String thymeleafView(){ return “mythymeleafview.html”; } @RequestMapping(“/view2”) public String … Read more

Why is an excerpt projection not applied automatically for a Spring Data REST item resource?

That works as designed. An excerpt projection is used whenever an instance of the target type (UserModel in your case) is used within in an _embedded clause. Thus the excerpt is some kind of preview used everywhere the resource itself is not rendered but pointed to. This is usually the case from collection resources or … Read more

Confused about how to handle CORS OPTIONS preflight requests

I sat down and debugged through the org.apache.catalina.filters.CorsFilter to figure out why the request was being forbidden. Hopefully this can help someone out in the future. According to the W3 CORS Spec Section 6.2 Preflight Requests, the preflight must reject the request if any header submitted does not match the allowed headers. The default configuration … Read more

Logging response body (HTML) from HttpServletResponse using Spring MVC HandlerInterceptorAdapter

This would be better done using a Servlet Filter rather than a Spring HandlerInterceptor, for the reason that a Filter is allowed to substitute the request and/or response objects, and you could use this mechanism to substitute the response with a wrapper which logs the response output. This would involve writing a subclass of HttpServletResponseWrapper, … 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

Custom Authentication Manager with Spring Security and Java Configuration

Take a look at my sample below. You have to return an UsernamePasswordAuthenticationToken. It contains the principal and the GrantedAuthorities. Hope I could help 🙂 public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getPrincipal() + “”; String password = authentication.getCredentials() + “”; User user = userRepo.findOne(username); if (user == null) { throw new … Read more