使用的是Spring3MVC_M2 版本
之前在Web.xml中配置如下
[code="xml"]
SpringMVC_Servlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/spring-app.xml,
/WEB-INF/spring-mybatis.xml,
/WEB-INF/spring-aop.xml,
/WEB-INF/spring-ehcache.xml
1
SpringMVC_Servlet
*.do
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-app.xml,
/WEB-INF/spring-mybatis.xml,
/WEB-INF/spring-aop.xml,
/WEB-INF/spring-ehcache.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
[/code]
[size=x-large]程序运行没问题,然后我在项目当中与Ehcache集成,导入Ehcache的jar包,然后增加配置如下[/size]
[code="xml"] <!-- 开启缓存对注解的支持 -->
<!-- 配置Ehcache缓存管理器,读取配置文件 -->
<bean id="ehCacheManagerFactoryBean" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"></property>
</bean>
<!-- 配置缓存管理器,获取cache -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" >
<property name="cacheManager" ref="ehCacheManagerFactoryBean" />
</bean>[/code]
[size=x-large]然后再启动就报错了
Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
[color=red]意思是说有重复的ID,因为以前配置过 所以我觉得肯定不是配置的原因,后来发现有一个地方不一样,那就是WEB.XML当中配置了ContextLoaderListener!!!我把它注释上启动就不报错了。
所以问题就来了。
1:为什么以前配置DispatcherServlet与ContextLoaderListener并不冲突,但是加上Eheache以后就说ID有重复。
2:我需要在程序当中得到Bean,所以我配置ContextLoaderListener。然后通过ServletContext拿到WebApplicationContext 最终得到Bean。如果我不配置ContextLoaderListener如何在Controller中得到Bean.
3: 请教一下 如果配置了DispatcherServlet 它不就会加载配置文件然后初始化Bean了吗 那还配置ContextLoaderListener有啥用,二者有什么区别。
[/color]
[/size]
[color=green][size=x-large]以上3点是我不解的地方 谢谢[/size][/color]