Spring Boot Application – View Resolver for Static Angular Pages.

Build Your Angular Project Into resources/static folder. You can specify the folder in angular.json file.

Here is the generated files.

Have your controller return a string “index”

@Controller
@CrossOrigin
public class HomepageController {


@RequestMapping({"/"})
public String index() {
return "index";
}
}

Then enable WebMVC and tweak some configuraitons. This should serve the index.html from the resources/static folder.

@Configuration
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {

@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setSuffix(".html");
return bean;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
}
}
[My Video Promotion]
Tagged , , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.