Jboss AS 7: Infinispam as Hibernate 2nd level cache
diegossilveira Dec 12, 2011 9:13 AMHello,
It's my first question here.
I've been trying to configure my application to use Infinispam (provided by JBoss AS 7) as Hibernate (3.5.6-Final) 2nd level cache.
My application is Spring 3 based, so here is the configuration of Hibernate Session Factory:
@Configuration
public class SessionFactoryContext {
@Resource
private DataSource dataSource;
@Bean( name = "sessionFactory" )
public AnnotationSessionFactoryBean sessionFactoryBean() {
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty( "hibernate.dialect", "org.hibernate.dialect.MySQLDialect" );
hibernateProperties.setProperty( "hibernate.show_sql", "true" );
hibernateProperties.setProperty( "hibernate.format_sql", "true" );
hibernateProperties.setProperty( "hibernate.use_sql_comments", "true" );
hibernateProperties.setProperty( "hibernate.connection.characterEncoding", "utf8" );
hibernateProperties.setProperty( "hibernate.cache.use_second_level_cache", "true" );
hibernateProperties.setProperty( "hibernate.cache.use_query_cache", "true" );
hibernateProperties.setProperty( "hibernate.cache.region.factory_class", "org.hibernate.cache.infinispan.JndiInfinispanRegionFactory" );
hibernateProperties.setProperty( "hibernate.cache.infinispan.cachemanager", "java:jboss/infinispan/hibernate-cache-container" );
AnnotationSessionFactoryBean sf = new AnnotationSessionFactoryBean();
sf.setDataSource( dataSource );
sf.setHibernateProperties( hibernateProperties );
sf.setPackagesToScan( ... );
return sf;
}
}
JBoss standalone.xml
<subsystem xmlns="urn:jboss:domain:infinispan:1.0" default-cache-container="hibernate-cache-container"> <cache-container name="hibernate-cache-container" default-cache="hibernate-cache"> <local-cache name="hibernate-cache"/> </cache-container> </subsystem>
MANIFEST.MF
Dependencies: org.infinispan export
The application works fine if I remove the hibernate properties "hibernate.cache.region.factory_class" and "hibernate.cache.infinispan.cachemanager", but with these properties I get the following exception while deploying the application at JBoss AS 7 (7.0.2.Final):
... 2011-12-12::11:56:56,904 INFO [org.jboss.as.clustering.infinispan.subsystem] (Controller Boot Thread) Activating Infinispan subsystem. ... 2011-12-12::11:57:16,058 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/api-checkout]] (MSC service thread 1-2) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'campaignInputTypeDAO' defined in "/content/api-checkout.war/WEB-INF/lib/pd-core-gateway-0.0.1-SNAPSHOT.jar/br/com/buscape/pd/gateway/model/impl/CampaignInputTypeDAOImpl.class": Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Error creating bean with name 'sessionFactory' defined in class path resource [br/com/buscape/pd/dbaccess/config/SessionFactoryContext.class]: Invocation of init method failed; nested exception is org.hibernate.cache.CacheException: Unable to start region factory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [br/com/buscape/pd/dbaccess/config/SessionFactoryContext.class]: Invocation of init method failed; nested exception is org.hibernate.cache.CacheException: Unable to start region factory at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [spring-context-3.0.6.RELEASE.jar:] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [spring-context-3.0.6.RELEASE.jar:] at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) [spring-web-3.0.6.RELEASE.jar:] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) [spring-web-3.0.6.RELEASE.jar:] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) [spring-web-3.0.6.RELEASE.jar:] at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final] at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final] at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26] at java.lang.Thread.run(Thread.java:662) [:1.6.0_26] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [br/com/buscape/pd/dbaccess/config/SessionFactoryContext.class]: Invocation of init method failed; nested exception is org.hibernate.cache.CacheException: Unable to start region factory at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) [spring-beans-3.0.6.RELEASE.jar:] ... 23 more Caused by: org.hibernate.cache.CacheException: Unable to start region factory at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:260) [hibernate-infinispan-3.5.6-Final.jar:] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:250) [hibernate-core-3.5.6-Final.jar:] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385) [hibernate-core-3.5.6-Final.jar:] at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954) [hibernate-annotations-3.5.6-Final.jar:] at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860) [spring-orm-3.0.6.RELEASE.jar:] at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779) [spring-orm-3.0.6.RELEASE.jar:] at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) [spring-orm-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) [spring-beans-3.0.6.RELEASE.jar:] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [spring-beans-3.0.6.RELEASE.jar:] ... 34 more Caused by: java.lang.IllegalStateException at org.jboss.msc.value.InjectedValue.getValue(InjectedValue.java:47) at org.jboss.as.naming.service.BinderService.getValue(BinderService.java:116) at org.jboss.as.naming.service.BinderService.getValue(BinderService.java:43) at org.jboss.msc.service.ServiceControllerImpl.getValue(ServiceControllerImpl.java:1216) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:111) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:73) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:173) at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:57) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:209) at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_26] at org.hibernate.cache.infinispan.JndiInfinispanRegionFactory.locateCacheManager(JndiInfinispanRegionFactory.java:75) [hibernate-infinispan-3.5.6-Final.jar:] at org.hibernate.cache.infinispan.JndiInfinispanRegionFactory.createCacheManager(JndiInfinispanRegionFactory.java:68) [hibernate-infinispan-3.5.6-Final.jar:] at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:246) [hibernate-infinispan-3.5.6-Final.jar:] ... 42 more
It looks like JBoss is not prepared to support the lookup of "java:jboss/infinispan/hibernate-cache-container" at the moment the session factory is instantiated by Spring, but the datasource ("java:jboss/datasources/dbpd03DS") is already bound and is succesfuly injected.
Can you help me please?
Thank you in advance.