【问题标题】:The method addListener(SessionListener) is undefined for the type ServletContextServletContext 类型的方法 addListener(SessionListener) 未定义
【发布时间】:2017-05-27 06:49:18
【问题描述】:

addListener(SessionListener) 方法中的未定义符号错误。这是我的sn-p:

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    super.onStartup(servletContext);       
    servletContext.addListener(new SessionListener());
}

我的 Maven 依赖项:

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.1.0</version> 
</dependency>

【问题讨论】:

    标签: java spring maven spring-security


    【解决方案1】:

    这个方法 addListener 是 3.0.0 版本的新方法,可能你的应用程序中有一个旧版本的 ServletContext 例如:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.3</version>
        <scope>provided</scope>
    </dependency>
    

    你需要从你的项目中排除这个,你可以在使用这个 servlet jar 的依赖项中使用排除标签来做到这一点。

    <exclusions>
        <exclusion>
            <artifactId>servlet-api</artifactId>
            <groupId>javax.servlet</groupId>
        </exclusion>
    </exclusions> 
    

    【讨论】:

      【解决方案2】:

      你的 servlet-api 版本是多少?

      我用的是 javax.servlet-api-3.1.0.jar ,有这个方法。

      【讨论】:

      • 我的依赖是 javax.servletjavax.servlet-api3.1.0
      猜你喜欢
      • 2011-10-27
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 2022-12-23
      • 2016-06-07
      相关资源
      最近更新 更多