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

Bean definition inheritance with annotations?

There is no notion of abstract bean in java config because the java language already has everything you need. Don’t forget that abstract beans are not exposed in the context at all, it’s some kind of template. You could rewrite your code above as follows: @Configuration public class Config { @Bean public DerivedTestBean() { DerivedTestBean … Read more

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

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

IllegalArgumentException: At least one JPA metamodel must be present

You have added <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> in your pom.xml. Spring boot will try automatically create an entity factory for JPA, but you do not have defined anything regarding JPA models. Try removing it in order to test what have you done so far. Afterwards you can check a tutorial using spring-data-starter-jpa like this guy

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 v3 no declaration can be found for element ‘mvc:resources’

In your spring context xml mvc namespace url should match url in schemaLocation. Something like this: <?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:mvc=”http://www.springframework.org/schema/mvc” xsi:schemaLocation=” http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd”> This is a standard XML namespace declaration. The namespace url is sort of an unique id, which is then mapped to the actual schema location in xsi:schemaLocation.