springmvc中使用多线程问题求解
我在springmvc中保存的时候要开启另一个线程发送邮件,邮件服务也是自己写的service,现在在thread里面要获取当前的applicationcontext,如ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext("file:D:\\workspaceXXXXXXXXXXXXX),然后再获取相应的bean,我的想法是这样的,但是在调试的时候,报错
Caused by: 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.ByteArrayInputStream@1e0eb8]
at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:457)
at net.sf.ehcache.CacheManager.init(CacheManager.java:354)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:322)
at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 36 more
public class SpringFactory implements ApplicationContextAware
{
private static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.context=applicationContext;
}
}