当前位置: 首页 > 知识库问答 >
问题:

简单ehcache项目异常

龚联
2023-03-14

我目前正在将一些项目转换为maven,并且在战争开始时遇到了一些问题。因此,我刚刚创建了一个非常简单的ehcache maven项目,我得到了一个类加载器类型的问题。这是我的POM:

<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.test</groupId>
<artifactId>MVCTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
    <spring.version>3.2.4.RELEASE</spring.version>
</properties>

<dependencies>

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

    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</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-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.ehcache-spring-annotations</groupId>
        <artifactId>ehcache-spring-annotations</artifactId>
        <version>1.2.0</version>
    </dependency>
</dependencies>
<build>
    <finalName>SpringMVC</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Spring Config: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/spring-context-3.0.xsd http://www.springframework.org/schema/context/spring-context/spring-context/spring-context-3.0.xsd

<context:component-scan base-package="com.test.common.controller" />


<ehcache:annotation-driven />

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
    <property name="cacheManager" ref="ehcache" />
</bean>

<bean id="ehcache"
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="/WEB-INF/ehcache.xml" />
</bean>

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

我在springmvc部分中还没有使用ehcache就已经有了HelloWorld类型的mvc设置。

我错过了什么?我假设它很简单,但我的项目看起来就像一个简单的ehcache项目的几乎所有hello world类型的配置。

共有1个答案

田兴朝
2023-03-14

Spring的EHCacheCheManager类充当EhCacheCacheManager实例的包装器。EHCacheManagerFactoryBean生成已经包装在EHCacheCheManager对象中的bean。所以基本上你是在尝试包装一个已经包装好的对象。相反,只需创建一个bean(使用工厂),您就会得到您想要的:

<bean id="cacheManager" 
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
  <property name="configLocation" value="/WEB-INF/ehcache.xml" />
</bean>

如果需要引用EhCacheCacheManager实例,则可以在此CacheManagerbean的getCacheManager()字段中获得该实例。

 类似资料:
  • 我试图建立一个简单的SpringMVC项目。 我创建了Web应用程序项目,然后添加了Spring和公共日志库。 还有这个网站。xml文件 这是HelloWebservlet。xml 然后我创建了java类(HelloContoller.java)com.tutorialspoint包 然后我在WEB-INF/JSP/hello中创建了JSP页面。jsp 我正在处理服务器glassfish,当我运行

  • 我正在使用Hibernate 5.1.0。最终版本为ehcache和Spring 3.2.11。释放。我在我的一个DAO中设置了以下可缓存注释: 要返回的项目有许多关联,其中一些是惰性的。例如,它(最终)引用字段: 我注意到,在我标记为Transactional的一个方法中,当从二级缓存中检索到上述方法时,我在尝试遍历categories字段时出现以下异常: 堆栈跟踪是: 我知道Hibernate

  • 为了配置一个简单的JPA项目,我使用了Wildfly 8,数据源是在单机版中配置的。xml。 在Web项目中,我配置了持久性。像这样的xml文件 http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 但是,当我添加br时。通用域名格式。卖应用程序。奥姆。通常,我在项目启动时出错,该错误表示存在hibernate问题org/hiber

  • 我正在尝试将缓存添加到springboot应用程序中,并且我遇到了一个问题,即在启动期间抛出org.ehcache.jsr107.MultiCacheException异常。 我使用的是以下(全部通过Maven pom文件加载):Springboot 1.5.5,Ehcache 3.3.1,Javax cache 1.0.0 我的SpringBootApplication看起来像这样: 我有一个包

  • 我有一个多模块项目,所有模块都在自己的ehcache中定义其缓存配置。xml。该用例由现在未维护的“ehcache spring annotations”项目通过以下配置解决: 我在Spring的缓存抽象中尝试了类似的东西。 然而,我遇到了这个例外: 有人能解释一下在多模块项目中为EhCache配置Spring缓存抽象的正确方法是什么吗?

  • 我正在尝试为一个简单的EJB项目编写一个客户端,我已经在本地部署了在Eclipse中运行的Wildfly 8。 我的界面: 我的实施: 我的客户: 当我运行它时,我得到这个异常: 官方文件也是这样:https://docs.jboss.org/author/display/AS71/EJB使用JNDI从远程客户端调用 问题出在哪里? 我在帖子中谈到了boss ejb客户端。属性,但我不知道该放什么