【问题标题】:Spring mvc cannot find CacheInterceptorSpring mvc 找不到 CacheInterceptor
【发布时间】:2018-07-06 13:33:57
【问题描述】:

我正在探索 spring mvc 框架中的缓存。按照herehere 等互联网指南,我正在配置:

<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:cache="http://www.springframework.org/schema/cache"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc.xsd
                http://www.springframework.org/schema/cache
                http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven />
... other configuration are omitted....
</beans>

在添加缓存配置之前,我的 Web 应用运行正常,现在,我的 Web 应用启动时出现错误:

java.lang.NoClassDefFoundError: org/springframework/cache/interceptor/CacheInterceptor

不知道我做错了什么?

【问题讨论】:

    标签: java spring spring-mvc caching


    【解决方案1】:

    NoClassDefFoundError 只是当 java 找不到另一个库使用的某个类时抛出的异常。

    这意味着当它被抛出时,你只需要把它放到类路径中。您可以通过转到库-> maven 依赖项(如果您使用的是 maven)-> 来确保它在那里,然后转到正在抛出的 noclassdef 的位置,在您的情况下,它将位于 org/springframework/cache/拦截器/缓存拦截器,这只是为了让您知道为什么会收到此错误,您现在不应该看到它。

    至于如何解决,这可能是因为 3 件事:

    1. 您的 maven 依赖项不在部署程序集上(库在项目中,但不在服务器上),但如果是这种情况,spring 可能根本无法工作。

    2. 你没有依赖,把这个加到pom.xml中:

      org.springframework 弹簧上下文 4.1.4.发布

    3. 你有冲突的 spring 版本,使所有版本标签相同。

    【讨论】:

    • 我根本不使用 Maven。我是 Java 世界的新手,我还没有使用过 Maven。所以,我没有 pom.xml 文件。正如你所描述的,我想我错过了 1 个或一些库,但仍然不知道如何获取它们。
    • @khoa_chung_89 您是如何获得其他图书馆的?这就是您获得所需任何其他库的方式。
    • @khoa_chung_89 好吧,我绝对建议在迁移到 Spring 之前学习 Java 基础知识和 maven。也就是说,如果您不使用 maven,请下载 jar 文件并手动添加。
    • @khoa_chung_89 但即使您不使用 maven,我提出的所有观点仍然适用,只需将 maven 替换为已安装的 jars
    • 我没有添加任何与spring cache相关的jar。我只是创建了一个基本的 spring web 项目,我认为缓存库应该默认存在。我已经阅读了一些文章,他们没有提到我必须添加任何库才能使用 spring 缓存。我同意我应该使用 maven,但即便如此,我怎么知道我错过了什么?如果我确切地知道问题(哪些库版本不匹配或缺少哪些库),我想我可以使用或不使用 maven 来解决它。
    猜你喜欢
    • 2019-08-13
    • 2015-01-15
    • 2015-03-31
    • 2023-03-05
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    相关资源
    最近更新 更多