似乎有另一个进程正在加载缓存,但无法定位这个(如果错误没有告诉我谎言)。它唯一告诉我的是,我有另一个缓存从一个名为InputStreamConfigurationSource的类开始???
有人遇到过这个错误吗???
我在用
StackTrace
SEVERE: Servlet.service() for servlet [SpringDispatcher] in context with path [/FileService] threw exception [com.sun.jersey.api.container.ContainerException: Unable to create resource class com.myapp.FileStoreAccessAction] with root cause
net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: InputStreamConfigurationSource [stream=java.io.BufferedInputStream@e782a8]
at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:521)
at net.sf.ehcache.CacheManager.init(CacheManager.java:371)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:356)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:191)
at com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:179)
at com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getInstance(PerRequestFactory.java:182)
at com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerRequest.getInstance(PerRequestFactory.java:144)
at com.sun.jersey.server.impl.application.WebApplicationImpl$19$1.getValue(WebApplicationImpl.java:1032)
at com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable$1.getValue(AbstractHttpContextInjectable.java:104)
at com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:196)
at com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:179)
at com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getInstance(PerRequestFactory.java:182)
at com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerRequest.getInstance(PerRequestFactory.java:144)
at com.sun.jersey.server.impl.application.WebApplicationImpl$19$1.getValue(WebApplicationImpl.java:1032)
at com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable$1.getValue(AbstractHttpContextInjectable.java:104)
at com.sun.jersey.server.spi.component.ResourceComponentInjector.inject(ResourceComponentInjector.java:222)
at com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:180)
at com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getInstance(PerRequestFactory.java:182)
at com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerRequest.getInstance(PerRequestFactory.java:144)
at com.sun.jersey.server.impl.application.WebApplicationContext.getResource(WebApplicationContext.java:238)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Spring配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Enable annotation configuration -->
<context:annotation-config/>
<context:component-scan base-package="com.myapp" />
<!-- Jackson JSON ObjectMapper -->
<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper" />
<!-- Cache Manager -->
<bean id="ehCacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" scope="singleton">
<property name="configLocation" value="classpath:cacheConfig.xml" />
<property name="shared" value="true"/>
</bean>
<!-- Data Access -->
<bean id="dataAccessFactory" class="com.myapp.DataAccessFactory" />
<!-- Application Stuff -->
<bean id="fileStoreService" class="com.myapp.FileStoreService" scope="singleton">
<constructor-arg ref="dataAccessFactory"/>
<constructor-arg ref="ehCacheManager" />
</bean>
</beans>
网页xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:appContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>SpringDispatcher</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringDispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
缓存文件
<ehcache>
<cache name="FileStoreList" maxElementsInMemory="10000" eternal="false"
overflowToDisk="false" timeToIdleSeconds="0" timeToLiveSeconds="0"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120" />
</ehcache>
文件服务类
public class FileStoreService {
private final CacheManager cacheFactory;
private final DataAccessFactory factory;
public FileStoreService(@InjectParam DataAccessFactory factory, @InjectParam CacheManager ehCacheManager) {
this.factory = factory;
cacheFactory = ehCacheManager;
}
...
JSONendpoint
public class FileStoreAccessAction {
/**
* JSON Object Mapper - pasted in via Spring
*/
@InjectParam
private ObjectMapper mapper;
@InjectParam()
private FileStoreService service;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response list() {
....
就像这个问题“泽西@InjectParam创建一个新对象而不是从Spring中获取”一样,使用了错误的servlet。所以有两个容器正在启动,一个通过“ContextLoaderListener”用于Spring,另一个通过“ServletContainer”用于泽西。这意味着正在启动缓存的两个实例。
使用的Servlet容器应该是
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
这样,球衣就可以连接到Spring容器上了
这就是我运行junit测试时发生的情况。。。 这一例外背后的原因是什么。是否有多个cacheManager同时运行? 这就是我使用Sping 3.1.1配置cachManager的方式。它明确地将cacheManager的范围设置为“singleton” 电子缓存。xml看起来像 终于上我的课了 我非常确定我的代码库中只有一个cacheManager。其他东西可能正在运行第n个实例。
我正在尝试将EhCache配置为在启用Apache Shiro的Web服务中处理授权缓存。目前我得到了以下例外: org.apache.shiro.cache.CacheException:net.sf.ehcache.CacheException:同一VM中已存在另一个未命名的CacheManager。请为配置中的每个CacheManager提供唯一名称,或执行以下操作之一: 使用CacheMa
这是网络。xml 当我检查日志时,我发现应用程序上下文被初始化了两次。我只是通过禁用dispatcher servlet的启动加载来验证它。当我禁用dispatcher servlet时,我发现异常不会在启动时出现。但它发生在我第一次尝试攻击任何控制器类时。 我在为什么Spring MVC需要至少两个上下文中发现了一些类似的问题? 在下面的链接中提到,对于Ehache2.5及更高版本,不允许同一J
问题内容: 这是我运行junit测试时发生的情况… 异常背后的原因是什么?可以同时运行1个以上的cacheManager吗? 这就是我使用Sping 3.1.1配置cachManager的方式。它将cacheManager的范围明确设置为“单例” The ehcache.xml looks like Finally my class 我非常确定我在代码库中只处理一个cacheManager。其他一
我想创建一个创建ArrayList的方法,并以现有ArrayList中的元素命名每个ArrayList。 就像原来是,我希望该方法创建四个ArrayList,分别命名为abc、def、ghi和jkl。