我正在尝试使用mvn clean install
运行我的测试,但这些错误会停止进程。我尝试使用JUNIT进行调试,但控制台上没有显示任何内容。
这些是日志:
com.datamint.service.impl.EmailServiceImplDevTest: Error creating bean with name 'entityManagerFactory' defined in class path resource [orm.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.methodSecurityMetadataSourceAdvisor': Cannot resolve reference to bean 'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource] while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.security.access.expression.method.ExpressionBasedAnnotationAttributeFactory] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'expressionHandler' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'expressionHandler' defined in class path resource [spring-security.xml]: Cannot resolve reference to bean 'permissionEvaluator' while setting bean property 'permissionEvaluator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'permissionEvaluator' defined in class path resource [spring-security.xml]: Cannot resolve reference to bean 'aclService' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclService' defined in class path resource [spring-security.xml]: Cannot resolve reference to bean 'lookupStrategy' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lookupStrategy' defined in class path resource [spring-security.xml]: Cannot resolve reference to bean 'aclCache' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclCache' defined in class path resource [spring-security.xml]: Cannot create inner bean 'org.springframework.cache.ehcache.EhCacheFactoryBean#a512c9c' of type [org.springframework.cache.ehcache.EhCacheFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.ehcache.EhCacheFactoryBean#a512c9c' defined in class path resource [spring-security.xml]: Cannot create inner bean 'org.springframework.cache.ehcache.EhCacheManagerFactoryBean#68394e81' of type [org.springframework.cache.ehcache.EhCacheManagerFactoryBean] while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.ehcache.EhCacheManagerFactoryBean#68394e81' defined in class path resource [spring-security.xml]: Invocation of init method failed; nested exception is 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:
可能是什么问题?感谢
答案 0 :(得分:1)
问题的原因是,使用默认设置,您不能让多个进程共享相同的EhCache。取自here
CacheManager支持两种创建模式:singleton和instance。
版本2.5之前的Ehcache版本允许任意数量的版本 具有相同名称(相同配置资源)的CacheManagers 存在于JVM中。因此,每次调用新的CacheManager(...)时, 创建了一个新的CacheManager而不考虑现有的 CacheManagers。调用CacheManager.create(...)返回现有的 具有配置名称的单一CacheManager(如果存在)或 基于传入的配置创建了单例。
Ehcache 2.5及更高版本不允许使用多个CacheManagers 相同名称存在于同一JVM中。 CacheManager()构造函数 创建非Singleton CacheManagers可能会违反此规则,从而导致 空指针异常。如果您的代码可能会创建多个CacheManagers 在同一个JVM中使用相同名称,通过使用静态来避免此错误 CacheManager.create()方法,它总是返回named(或 默认未命名)CacheManager(如果它已存在于该JVM中)。如果 命名(或默认未命名)CacheManager不存在, CacheManager.create()方法创建它。
解决问题的一个解决方案(但会减慢测试的执行速度)是为每个加载Spring配置的测试添加@DirtiesContext
。这将迫使Spring在运行每个测试类时重新创建所有bean,并且您将能够回避问题。
在这些情况下我更喜欢的解决方案是使用不配置缓存的不同配置文件来运行测试(不测试缓存)。那样你就不需要@DirtiesContext
,因此测试的执行时间要好得多