`
sxdtzhaoxinguo
  • 浏览: 228543 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Spring,ehcache整合报错

 
阅读更多

摘要:在做Spring整合ehcache配置的时候出现了下面的错误,提示如下:java.lang.ClassNotFoundException: org.springframework.cache.ehcache.EhCacheManagerFactoryBean,经过检查发现是因为org.springframework.cache.ehcache.EhCacheManagerFactoryBean包是从spring-context-support.jar引入的,所有还需要引入该jar才行,否则还是找不到该类。


一:错误信息如下:

T E S T S
-------------------------------------------------------
Running com.microcampus.ehcache.test.EhcacheTest
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.707 sec <<< FAILURE!
test(com.microcampus.ehcache.test.EhcacheTest)  Time elapsed: 0.015 sec  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94)
	at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:252)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:254)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.cache.ehcache.EhCacheManagerFactoryBean] for bean with name 'cacheManager' defined in class path resource [applicationContext-test.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.cache.ehcache.EhCacheManagerFactoryBean
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)
	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)
	... 31 more
Caused by: java.lang.ClassNotFoundException: org.springframework.cache.ehcache.EhCacheManagerFactoryBean
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
	... 44 more


Results :

Tests in error: 
  test(com.microcampus.ehcache.test.EhcacheTest): Failed to load ApplicationContext

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

重点是这里:Caused by: java.lang.ClassNotFoundException: org.springframework.cache.ehcache.EhCacheManagerFactoryBean


二:pom.xml引入的jar如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.microcampus.ehcache</groupId>
	<artifactId>ehcache</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>ehcache</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<springframework.version>4.1.4.RELEASE</springframework.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${springframework.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- ehcache 2.x核心jar -->
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache</artifactId>
			<version>2.10.2</version>
		</dependency>
		<!-- ehcache-web主要针对页面缓存 -->
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache-web</artifactId>
			<version>2.0.4</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-expression</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>3.2.0</version>
		</dependency>
		<dependency>
			<groupId>asm</groupId>
			<artifactId>asm</artifactId>
			<version>3.3</version>
		</dependency>
	</dependencies>
</project>

引入上面的jar后,再次执行测试命令就可以成功了,最后我把Spring+Ehcache整合实现缓存的Demo上传上来,下载地址如下:

http://download.csdn.net/detail/sxdtzhaoxinguo/9532090



分享到:
评论

相关推荐

    spring3整合EhCache注解实例

    spring3整合EhCache注解实例

    整合spring 和ehcache

    配置ehcache缓存,存储内存的设置,与spring 的整合等

    Ehcache 整合Spring 使用页面、对象缓存

    通过上述步骤,Ehcache 可以有效地整合到Spring环境中,实现页面和对象级别的缓存,从而显著提高应用程序的性能。同时,Ehcache的灵活性和扩展性使得它能够适应各种复杂的应用场景,满足不同项目的需求。

    spring struts2 hibernate ehcache整合

    这篇博客“spring struts2 hibernate ehcache整合”显然探讨了如何将这四个组件集成到同一个项目中,以提升应用程序的性能和效率。以下是关于这些技术及其整合的关键知识点的详细说明: 1. **Spring框架**:Spring...

    spring整合ehCache

    Spring整合EhCache是将EhCache作为一个缓存解决方案与Spring框架进行集成,以提高应用程序的性能和效率。EhCache是一款开源、轻量级的Java缓存库,广泛用于缓存中间件,以减少数据库访问,提升系统响应速度。 在...

    Spring4 整合EhCache实现 页面缓存 零配置

    在本文中,我们将深入探讨如何使用Spring4框架与EhCache进行整合,以实现零配置的页面缓存功能。EhCache是一个广泛使用的开源Java缓存解决方案,它提供了高效的内存和磁盘缓存机制,有助于提升应用程序性能。通过...

    Spring+Hibernate+ehcache整合

    在"Spring+Hibernate+ehcache整合"项目中,开发者已经完成了一个将这三个框架集成的基础工程。虽然Struts没有被明确提及,但通常在Web开发中,Spring与Struts结合可以构建更完整的MVC架构。这个整合项目可能包含以下...

    springMVC+mybatis+ehcache整合

    在Spring中整合Ehcache,可以通过Spring的缓存抽象进行配置,定义缓存注解如`@Cacheable`、`@CacheEvict`、`@CachePut`来控制缓存的存取和清除。Ehcache的配置文件(ehcache.xml)可以指定缓存的大小、存活时间和...

    spring+ehcache示例整合Demo

    在这个"spring+ehcache示例整合Demo"中,我们将会探讨如何将Ehcache集成到Spring框架中,以实现高效的缓存管理。 首先,我们需要在项目的`pom.xml`文件中引入Ehcache和Spring的依赖。Ehcache通常使用的是`org....

    Ehcache整合Spring使用页面、对象缓存

    在Spring框架中整合Ehcache,可以实现页面和对象级别的缓存管理,从而优化Web应用的响应速度。下面将详细介绍Ehcache与Spring的整合及其在页面和对象缓存中的应用。 一、Ehcache简介 Ehcache是基于内存的分布式缓存...

    Spring+Ehcache集成

    **Spring与Ehcache集成详解** 在现代Java应用开发中,缓存技术是提升系统性能的关键环节。Ehcache作为一款流行的开源缓存解决方案,因其轻量级、高性能和易于集成的特点,常被广泛应用于Spring框架中。本篇文章将...

    spring+ibatis+ehcache整合例子

    这个"spring+ibatis+ehcache整合例子"是一个完整的示例项目,展示了如何将这三个框架无缝集成到一个基于MySQL数据库的应用中。下面将详细介绍这三个框架及其整合的关键点。 **Spring框架** Spring是一个全面的企业...

    Spring+ehcache整合

    本教程将深入探讨如何在Spring 4.1版本中整合Ehcache 2.10.2,实现高效的缓存功能。 首先,让我们了解Ehcache的基本概念。Ehcache是一个开源的、基于内存的分布式缓存系统,支持本地缓存、分布式缓存以及 ...

    ehcache+spring demo 整合

    将 Ehcache 整合到 Spring 中,可以方便地在Spring应用中使用缓存服务。 在"ehcache+spring demo 整合"项目中,我们有两个工程:一个Web工程和一个Java工程。Web工程通常用于构建前端展示和处理HTTP请求,而Java...

    Struts2+Spring+Hibernate+Ehcache+AJAX+JQuery+Oracle 框架集成用户登录注册Demo工程

    1.通过google ehcache-spring-annotatios.jar自动注解方式实现整合Spring+Ehcache。 2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。...

    spring2.5整合ehcache2.0使用

    在本文中,我们将深入探讨如何将Spring 2.5与Ehcache 2.0进行集成,以便在我们的应用程序中实现高效、可扩展的缓存管理。Ehcache是一款广泛使用的开源Java缓存解决方案,而Spring框架则为它提供了一个方便的集成层,...

    spring整合EhCache 的简单例子

    Spring 整合 EhCache 是一个常见的缓存管理方案,它允许我们在Spring应用中高效地缓存数据,提高系统性能。EhCache 是一个开源、基于内存的Java缓存库,适用于快速、轻量级的数据存储。现在我们来详细探讨如何在...

    spring集成ehcache所需的jar包

    spring集成ehcache所需的jar包

    spring+ehcache

    本文将深入探讨如何将Ehcache与Spring进行整合,以提高应用程序的性能和效率,主要基于提供的"spring+ehcache"入门级别的demo。我们将通过JUnit进行测试,确保整合过程正确无误。 **一、Spring与Ehcache的整合** 1...

Global site tag (gtag.js) - Google Analytics