所以我刚刚把我的Spring Boot web应用升级到了2.0.0,在我的主Application类中,我有这个方法:
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
if (rootAppContext != null) {
servletContext.addListener(new RequestContextListener());
}
else {
logger.debug("No ContextLoaderListener registered");
}
}但是现在我得到了一个编译错误:
The method addListener(RequestContextListener) is undefined for the type ServletContext奇怪的是ServletContext才是问题所在,而不是Spring boot。它不再有任何add*方法。Spring5/Boot2是否升级了servlet规范,现在正确的做法是什么?
发布于 2018-03-03 00:54:59
这是一个ServletContext的问题。Spring boot 2使用servlet规范3.1.0,显然不再支持2.5,这是我的pom中的版本。因此,我将其替换为:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency> 它运行得很好。希望这对某些人有帮助。
https://stackoverflow.com/questions/49071434
复制相似问题