Announcement Announcement Module
Collapse
No announcement yet.
java.lang.IllegalStateException: 'cacheManager' is required Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.IllegalStateException: 'cacheManager' is required

    Hi,

    while moving my spring framwork out of my WAR file into the JBoss modules structure and depending on it via jboss-dployment-structure.xml I'm getting a strange error:

    Code:
    Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'middlewareApplicationContext' defined in "/D:/my.war/WEB-INF/classes/my/path/to/MiddlewareApplicationContext.class": BeanPostProcessor before instantiation of bean failed;
    
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor' defined in class path resource [org/springframework/cache/annotation/ProxyCachingConfiguration.class]: Instantiation of bean failed; 
    
    nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor org.springframework.cache.annotation.ProxyCachingConfiguration.cacheAdvisor()] threw exception; 
    
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheInterceptor' defined in class path resource [org/springframework/cache/annotation/ProxyCachingConfiguration.class]: Invocation of init method failed; 
    
    nested exception is java.lang.IllegalStateException: 'cacheManager' is required
    
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:457) [spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) [spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    	at org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:44) [resteasy-spring-2.2.1.GA.jar:]
    	at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.17.Final-redhat-1.jar:]
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.17.Final-redhat-1.jar:]
    	at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:89) [jboss-as-web-7.1.3.Final-redhat-4.jar:7.1.3.Final-redhat-4]
    	at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_38]
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_38]
    	at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_38]
    I guess, the problem is, that I have no bean definiton for a CacheManager. But - I have. Inside my WAR file, is a JAR file (with common used stuff), and this has a Bean annotated CacheManager in it:

    Code:
    @Profile(value = { MiddlewareConfiguration.PROFILE_DEVELOPMENT, MiddlewareConfiguration.PROFILE_TEST })
    @Configuration
    @EnableCaching
    public class InfinispanCacheConfiguration implements CachingConfigurer {
    [...]
    	@Bean
    	@Singleton
    	public SpringRemoteCacheManagerFactoryBean remoteCacheManagerFactoryBean() {
    		final SpringRemoteCacheManagerFactoryBean cacheManagerFactoryBean = new SpringRemoteCacheManagerFactoryBean();
    		final String serverlist = this.environment.getProperty(INFINISPAN_REMOTE_SERVERLIST);
    		Properties configurationProperties = new Properties();
    		configurationProperties.setProperty(INFINISPAN_REMOTE_SERVERLIST, serverlist);
    		cacheManagerFactoryBean.setConfigurationProperties(configurationProperties);
    		return cacheManagerFactoryBean;
    	}
    
    	@Override
    	@Bean
    	@Singleton
    	public CacheManager cacheManager() {
    		final SpringRemoteCacheManagerFactoryBean remoteCacheManagerFactoryBean = this.remoteCacheManagerFactoryBean();
    		SpringRemoteCacheManager cacheManager;
    		try {
    			cacheManager = remoteCacheManagerFactoryBean.getObject();
    		} catch (Exception e) {
    			throw new RuntimeException(e);
    		}
    		LOGGER.debug("Infinispan CacheManager has been initialized.");
    		return cacheManager;
    	}
    [...]
    }
    This works perfectly fine while spring is included in the WAR file. If it is loaded via jboss-deployment-structure.xml the above pasted exception is raised. My guess is, that Spring does not find my cacheManager Bean and therfore cacheManager is null in org.springframework.cache.interceptor.CacheAspectS upport.afterPropertiesSet.

    How can I fix this? Can I configure something in my WAR file to tell spring that the CacheManager-Bean is located in JAR file which is inclued in the WAR?

  • #2
    I tried now to load my JAR file which contains the @Bean definition for cacheManager also as JBoss module hoping that in this case with spring as a dependency of this module will catch up the definition. But - same error.... did none managed to load spring as JBoss module for their application together with a cache manager?

    Comment

    Working...
    X