【问题标题】:Spring 4 does not import EhCacheSpring 4 不导入 EhCache
【发布时间】:2019-11-27 16:40:07
【问题描述】:

在将项目从 Spring 3 迁移到 Spring 4(使用 IntelliJ 和 Maven)时,我遇到了这个导入的 EhCache 包的问题:

错误:(13,40)java:错误:包org.springframework.cache.ehcache不存在

分析问题,我发现 Spring 3 是从 spring-context-support 导入 ehCache 包,该包包含在 maven 的 spring-core 依赖项中。

Spring 4 的 spring-core 不包括包含 ehcache 包的 spring-context-support,因此我手动将 spring-context-support 的依赖项添加到 POM 中:

pom.xml

  <spring.version>4.3.25.RELEASE</spring.version>
  <ehcache.version>2.5.0</ehcache.version>

  (...)

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
  </dependency>

  (...)

  <dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>${ehcache.version}</version>
  </dependency>

但是,根本没有导入依赖项。仅导入不包含 ehCache 包的 spring-context 库:

春季 3:

春季 4

我尝试过的事情:

  • mvn 全新安装
  • 使用 IntelliJ 重新导入 maven 依赖项
  • 删除 .idea 文件夹并重新启动 IntelliJ 以强制导入依赖项
  • 删除 .m2 文件夹

我在这里做错了什么?如何将 EhCache 与 spring 4 和 maven 一起使用?

【问题讨论】:

    标签: spring maven intellij-idea ehcache


    【解决方案1】:

    我认为 ehcache 的依赖应该是

    <dependency>
        <groupId>org.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>3.8.1</version>
    </dependency>
    

    当您勾选here时,表明该工件已移至上述那个。

    【讨论】:

    • 你的建议我试过了,可惜还是不行
    • org.ehcache 版本 3.8.1,就像您的示例中一样
    【解决方案2】:

    最可能的解释是您的 Maven 设置不正确。

    你能在你添加spring-context-support版本4.3.25的项目中运行mvn dependencies:tree吗?

    这将告诉您 Maven 是否看到该依赖项。 如果没有,我会检查您编辑的文件与您正在测试的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-04
      • 1970-01-01
      • 2014-03-23
      • 2017-09-19
      • 2018-05-30
      • 1970-01-01
      • 2018-01-25
      相关资源
      最近更新 更多