小编ask*_*332的帖子

WebMvcConfigurerAdapter不起作用

这是我正在处理的WebConfig代码:

package hello.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/greeting").setViewName("greeting");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的Application.class

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@SpringBootApplication
public class Application extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

}
Run Code Online (Sandbox Code Playgroud)

这似乎是一个Spring-boot问题,在某些系统中不会调用这些类方法.相应的问题报告在:https: //github.com/spring-projects/spring-boot/issues/2870

我的问题是,我们可以将此类中映射的资源映射到此类之外作为临时解决方法吗?

如果是,我们该怎么做?

更新:按照Andy Wilkinson的建议我删除@EnableWebMvc了,演示应用程序开始工作.然后我尝试逐个删除项目文件,以查看错误消失的点.我发现我在项目中有两个类,一个是扩展的WebMvcConfigurationSupport,第二个来自WebMvcConfigurerAdapter.从项目中删除前一个类修复了错误. …

spring spring-mvc spring-boot

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

spring ×1

spring-boot ×1

spring-mvc ×1