EHcache 与 Spring 配置 + Jdbc模板

发布于 2024-12-27 22:54:38 字数 2538 浏览 0 评论 0原文

我正在尝试使用 spring 3.0 实现缓存,

这是与集成相关的代码:

<bean id="cacheManager" class="net.sf.ehcache.CacheManager">
    <constructor-arg index="0" type="java.net.URL" value="classpath:ehcache.xml"/>
</bean>

在 application-context.xml 文件中,

我有一个有效的 ehcache.xml 文件,但它从未被读取,因为应用程序在到达那里之前就崩溃了,我收到的错误如下:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [net.sf.ehcache.CacheManager] for bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/spring/application-context.xml]; nested exception is java.lang.ClassNotFoundException: net.sf.ehcache.CacheManager
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1208)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:568)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:302)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:185)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:805)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:762)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:680)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:556)
... 30 more
Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.CacheManager
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:258)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1229)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1200)

有人知道我做错了什么吗?

I'm trying to implement cache with spring 3.0

Here is the code that is relevant to the integration:

<bean id="cacheManager" class="net.sf.ehcache.CacheManager">
    <constructor-arg index="0" type="java.net.URL" value="classpath:ehcache.xml"/>
</bean>

In application-context.xml file

I have a valid ehcache.xml file but it's never read since the application bombs before it gets there, the error I'm receiving is the following:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [net.sf.ehcache.CacheManager] for bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/spring/application-context.xml]; nested exception is java.lang.ClassNotFoundException: net.sf.ehcache.CacheManager
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1208)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:568)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:302)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:185)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:805)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:762)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:680)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:556)
... 30 more
Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.CacheManager
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:258)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1229)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1200)

Does anyone have an idea of what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷→糖丶微凉 2025-01-03 22:54:39

请将您的 ehcache jar 添加到 web-inf/lib 目录。

如果您使用 Maven,请将其添加到您的 pom.xml 中。

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>2.4.7</version>
</dependency>

Please add your ehcache jars to web-inf/lib directory.

If you are using Maven than add this to your pom.xml.

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>2.4.7</version>
</dependency>
森罗 2025-01-03 22:54:39

如果您从 eclipse 启动项目,请检查您是否已将 ehcache 库添加到“部署程序集”列表中。

打开项目的属性对话框 -> “部署程序集”并在那里添加库。

If you start your project out of eclipse, check if you have added the ehcache library to the "Deployment Assembly" list.

Open your project's properties dialog -> "Deployment Assembly" and add the lib there.

hth

暮倦 2025-01-03 22:54:39

似乎您应该将 ehcache-core jar 添加到您的类路径中...但请注意添加正确的版本。

编辑:

请注意,ehcache 用于 artifactId,而不是 ehcache-core

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>1.6.1</version>
</dependency>

再次运行 mvn install 后,确保正确的 jar 驻留在本地存储库中并且包含正确的类。

Seems you should add ehcache-core jar to your classpath... Note to add the right version, though.

EDIT:

note that ehcache is used in the artifactId and not ehcache-core.

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>1.6.1</version>
</dependency>

After running mvn install again, make sure the right jar resides in your local repository and that it contains the right class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文