- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我正在处理的 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");
}
}
这是我的 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);
}
}
在某些系统中这些类方法不会被调用,这似乎是一个 spring-boot 问题。相应的问题报告于: https://github.com/spring-projects/spring-boot/issues/2870
我的问题是,我们可以将此类中映射的资源映射到此类之外,作为临时解决方法吗?
如果是,我们该怎么做?
更新:按照 Andy Wilkinson 的建议,我删除了 @EnableWebMvc
并且演示应用程序开始运行。然后我尝试将项目文件一一剥离,看看错误在什么时候消失。我发现项目中有两个类,一个是从 WebMvcConfigurationSupport
扩展的,第二个是从 WebMvcConfigurerAdapter
扩展的。从项目中删除前一个类修复了错误。
我想知道的是,为什么会发生这种情况?其次,为什么这个错误不是在所有系统上都出现?
最佳答案
问题是 WebConfig
位于 config
包和Application
位于 hello
包裹。 @SpringBootApplication
上Application
启用对其声明的包及其子包的组件扫描。在这种情况下,这意味着 hello
是组件扫描的基础包,因此 WebConfig
在 config
从未找到包。
为了解决这个问题,我会移动WebConfig
进入hello
包或子包,例如 hello.config
.
您在 GitHub 上的最新更新已更改 WebConfig
从延伸WebMvcConfigurerAdapter
延伸WebMvcConfigurationSupport
。 WebMvcConfigurationSupport
是 @EnableWebMvc
导入的类所以用 @EnableWebMvc
注释你的类并延伸WebMvcConfigurationSupport
将配置两次。您应该返回扩展 WebMvcConfigurerAdapter
就像以前一样。
关于spring - WebMvcConfigurerAdapter 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30910642/
这是我正在处理的 WebConfig 代码: package hello.config; import org.springframework.context.annotation.Configura
我已经在 Spring MVC 中使用以下代码将 xml 转换为 Java 类。谁能告诉我如何设置 bean 创建的顺序。当我运行以下代码时。 JDBCTemplate bean 在 DataSour
我在我的 Spring Boot 应用程序中成功地使用了 @EnableSpringDataWebSupport 来启用分页、排序等等。然而,在某些时候,我不得不引入一个自定义参数解析器,并使用 Ja
我只是迁移到 spring mvc 版本 5.0.1.RELEASE 但突然在 eclipse STS WebMvcConfigurerAdapter 被标记为已弃用 public class Mvc
我正在尝试在 Spring Boot 应用程序中实现转换器,但由于某种原因,我对 addFormatters(FormatterRegistry formatterRegistry) 的重写从未被调用
注意以前已将其标记为已回答,但是随着我对基本组件的理解得到了改善,我看到我们的最初答案仅解决了空指针,但未解决根本原因。目前,根本原因似乎是缺少对分发侦听器和附加到容器的dwrServlet上上下文的
我想在 Windows 中使用 WebMvcConfigurerAdapter 添加资源处理程序,但在 Linux 中它不起作用,所以我添加了 WebMvcConfigurationSupport。
我想添加资源处理程序。在论坛中,他们使用 WebMvcConfigurationSupport:http://forum.springsource.org/showthread.php?116068-
由于 WebMvcConfigurerAdapter 从 Spring 5.0 开始已被弃用,我已将其更改为 WebMvcConfigurationSupport,但我得到的响应为空值。 { "key
我的应用有以下配置: @EnableTransactionManagement @EnableWebSecurity public class SecurityApiConfiguration e
有2个配置,在不同的jar文件中,我想控制拦截器注册的顺序。一个拦截器可能依赖于另一个拦截器设置的数据。 我已经在 addInterceptors 方法上尝试过 @Order。 @Configurat
我有一个使用 Spring Security 和 Thymeleaf 模板的 Spring Boot 应用程序。当 Controller 由 WebConfigurerAdapter 的子类管理时,我
我可以同时使用以下配置吗? 和 @Configuration @EnableWebMvc public class ResourceMappingsAdapter extends WebMvcCon
我想将两个配置合并为一个配置。这是它们目前的样子: WebMvcConfigurerAdapter @Configuration @EnableWebMvc @Import(...) public c
我有一个用于 web 的 Spring Boot hello world 和一些配置混淆: Spring 版本:1.2.6.RELEASE 我的项目结构: 我需要提供一些静态内容,所以我决定在一些自定
我是一名优秀的程序员,十分优秀!