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”)); }; } }

Custom Authentication provider with Spring Security and Java Config

The following does what you need (CustomAuthenticationProvider is your implementation which needs to be managed by Spring) @Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private CustomAuthenticationProvider customAuthenticationProvider; @Override protected void configure(HttpSecurity http) throws Exception { /** * Do your stuff here */ } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(customAuthenticationProvider); } … 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

How to apply Spring Data projections in a Spring MVC controllers?

No it’s not, especially as projections are usually applied to the result of a query execution on a case by case basis. Thus they’re currently designed to be selectively applied to domain types. As of the latest Spring Data Fowler release train GA release the projection infrastructure can be used programmatically in Spring MVC controllers. … 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

spring property substitution for test and production

several approaches: 1. ‘Order’ Property in src/main/resources/your-conf.xml <context:property-placeholder location=”classpath:esb-project-config.properties” order=”1″/> in src/test/resources/your-test-config.xml <context:property-placeholder location=”classpath:esb-project-config.properties” order=”0″/> If you running your test with src/test/resources as a test classpath, the above will ensure to override src/main/resources/esb-project-config.properties with the src/test/resources/esb-project-config.properties. This will override the whole property-placeholder though, so you would have to provide all the properties needed in your … Read more

Spring/Rest @PathVariable character encoding

I thing that you need add filter to web.xml <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

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

Multiple data source and schema creation in Spring Boot

spring.jpa.hibernate.ddl-auto=create has stopped working, not because you have two DataSources, but because your application’s creating its own LocalContainerEntityManagerFactoryBeans. This has the effect of disabling the auto-configuration of a LocalContainerEntityManagerFactoryBean so you now have to configure it yourself. You can configure the two entity managers to have different schema generation behaviour like this (the first’s doing … Read more