小菜鸟学习spring boot --接管spring boot的web配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小菜鸟学习spring boot --接管spring boot的web配置相关的知识,希望对你有一定的参考价值。
菜鸟新来,大神勿喷,些许醍醐,感激涕零。因为 我总是装幽默,是因为我想让自己快乐。
- spring boot提供的spring mvc 不符合自己的需求,自己则可以编写一个控制类 加上 @EnableWebMvc注解 来自己控制mvc配置。
- spring boot提供的spring mvc 既需要保留,又需要添加自己的配置的时候,可以自定义一个WebMvcConfigureAdapter,而不需要使用EnableWebMvc注解;
1 @Configuration 2 public class WebConfig extends WebMvcConfigurerAdapter{ 3 @Override 4 public void addViewControllers(ViewControllerRegistry registry) { 5 registry.addViewController("/xx").setViewName("/xx"); 6 } 7 }
这里的addViewControllers方法并不会覆盖 WebMvcAutoConfiguration 中的addViewControllers方法;也就是说我们可以同时使用。
以上是关于小菜鸟学习spring boot --接管spring boot的web配置的主要内容,如果未能解决你的问题,请参考以下文章