Error creating Job in Spring Batch - spring

I'm using JDeveloper and Weblogic 12c(12.1.3) and I want to create a job with XML using Spring Batch. When I deploy the project It shows me and error. I need to use this IDE because of some restrictions in my job, also, without using maven.
I've seen several example and I think my XML it's fine. I think the problem is related to weblogic (I had a similar issue) because I made the same test with the same project structure and libraries using Netbeans IDE and GlassFish Open Source Edition 4.1.1, and it works.
The libraries
aopalliance-1.0.jar
com.ibm.jbatch-tck-spi-1.0.jar
commons-logging-1.1.3.jar
hsqldb-2.3.3.jar
javax.batch-api-1.0.jar
jettison-1.2.jar
spring-aop-4.0.5.RELEASE.jar
spring-batch-core-3.0.5.RELEASE.jar
spring-batch-infrastructure-3.0.5.RELEASE.jar
spring-beans-4.0.5.RELEASE.jar
spring-context-4.0.5.RELEASE.jar
spring-core-4.0.5.RELEASE.jar
spring-expression-4.0.5.RELEASE.jar
spring-jdbc-4.0.5.RELEASE.jar
spring-retry-1.1.0.RELEASE.jar
spring-tx-4.0.5.RELEASE.jar
spring-web-4.0.5.RELEASE.jar
spring-webmvc-4.0.5.RELEASE.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.7.jar
The error
<org.springframework.web.servlet.FrameworkServlet> <FrameworkServlet> <initServletBean> <Context initialization failed>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncherController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.batch.core.Job batch.JobLauncherController.job; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'job': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:402)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:316)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:282)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
at javax.servlet.GenericServlet.init(GenericServlet.java:240)
My application context XML is this:
testBatch-servlet.xml
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="batch"/>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/"/>
<beans:property name="suffix" value=".jsp"/>
</beans:bean>
<beans:bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"></beans:bean>
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<beans:property name="url" value="jdbc:oracle:thin:#//localhost:1521/xe"/>
<beans:property name="username" value="system"/>
<beans:property name="password" value="1234"/>
</beans:bean>
<beans:bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<beans:property name="jobRepository" ref="jobRepository"/>
<beans:property name="taskExecutor">
<beans:bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
</beans:property>
</beans:bean>
<beans:bean id="myTasklet" class="batch.MyTasklet"></beans:bean>
<job id="job" job-repository="jobRepository">
<step id="test" >
<tasklet ref="myTasklet"/>
</step>
</job>
</beans:beans>
any ideas?

This is a workaround if I don't want to touch my weblogic.xml, but I can't use the new features of Spring Batch.
I have to use Spring Batch 2.2.7 to work with Weblogic 12.1.3, I created again a project with maven to find the dependencies. So the dependencies should be as follows:
aopalliance-1.0.jar
commons-logging-1.1.3.jar
jettison-1.1.jar
spring-aop-3.2.9.RELEASE.jar
spring-batch-core-2.2.7.RELEASE.jar
spring-batch-infrastructure-2.2.7.RELEASE.jar
spring-beans-3.2.9.RELEASE.jar
spring-context-3.2.9.RELEASE.jar
spring-core-3.2.9.RELEASE.jar
spring-expression-3.2.9.RELEASE.jar
spring-retry-1.0.2.RELEASE.jar
spring-tx-3.2.9.RELEASE.jar
spring-web-3.2.9.RELEASE.jar
spring-webmvc-3.2.9.RELEASE.jar
xpp3_min-1.1.4c.jar
xstream-1.3.jar
I hope there is a supported version of Spring Batch soon. I found that Weblogic already supports Spring but I don't know in what level.

I think you must use Filtering Classloading including the version of Spring you need.
http://docs.oracle.com/cd/E12839_01/web.1111/e13706/classloading.htm
If it is a war file then add true to weblogic.xml
That version is supported in WLS 12.1.3 :
WLS 12.1.3 Spring Framework versions 3.0.x, 3.1.x, and 4.0.x (note that version 3.2.x is not supported) (not-supported doesn't mean won't work).

Related

Spring and Hibernate Application with Websphere

I am facing problem in deploying my application to Websphere 8.5
I am trying to build an application with Hibernate 5, Spring 5 and WebSphere 8.5. I am not able to build sessionFactory Object in my project. Not sure where the problem is. Whether wrt to dependency or I did something wrong.
Here's how I am getting my session.
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/bdcp_01_ORA_XA"/>
</bean>
<!-- Hibernate Session Factory -->
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<!-- Hibernate configuration -->
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
</beans:props>
</beans:property>
<!-- The packages that contain our Hibernate model classes -->
<beans:property name="packagesToScan">
<beans:list>
<beans:value>com.gssc.model</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<!-- Hibernate transaction management -->
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
Getting error as Shown below:-
Error creating bean with name 'sessionFactory' defined in
ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation
of init method failed; nested exception is
java.lang.NoSuchMethodError:
javax/persistence/Table.indexes()[Ljavax/persistence/Index;
Also if I change the version as mentioned above, which version shall i move ahead. And shall i create sessionFactory as mentioned.
Please help

IBM WAS Liberty Error + missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource

I'm converting a glassfish project over to IBM WAS Liberty, with much difficulty I am presently having an issue accessing my connection pool configured in Liberty (server.xml) utilizing jndi (jdbc/dataphile).
I contuinually get a missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource error.
Here is some more added detail:
<library id="DB2JCC4Lib">
<fileset dir="C:/MyApps/db2/jdbc" id="db-fileset" includes="db2jcc4-9.5.jar"/>
</library>
<dataSource id="dataSource" jndiName="jdbc/dataphile" type="javax.sql.DataSource">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<connectionManager minPoolSize="2" numConnectionsPerThreadLocal="10"/>
<properties.db2.jcc databaseName="DUNDEEPD" id="DataphileProperties" password="username" portNumber="30001" serverName="xxx.xx.xxx.xxx" user="username"/>
</dataSource>
My stack trace is below;
[ERROR ] Context initialization failed
Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine modifiers of missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource
[Xlint:cantFindType]
at org.aspectj.weaver.reflect.ReflectionWorld$ExceptionBasedMessageHandler.handleMessage(ReflectionWorld.java:129)
at org.aspectj.weaver.Lint$Kind.signal(Lint.java:340)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:232)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.getModifiers(MissingResolvedTypeWithKnownSignature.java:104)
at org.aspectj.weaver.ResolvedType.isInterface(ResolvedType.java:876)
at org.aspectj.weaver.ResolvedType.getHierarchy(ResolvedType.java:355)
at org.aspectj.weaver.patterns.KindedPointcut.fastMatch(KindedPointcut.java:126)
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.couldMatchJoinPointsInType(PointcutExpressionImpl.java:84)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:238)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:200)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:254)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:286)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1561)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:162)
... 58 more
I am not an expert on this but a similar problem was reported here:
https://developer.ibm.com/answers/questions/9498/datasource-issue-on-liberty-in-spring-hibernate-application.html
The solution required adding this to the datasource:
<property name="resourceRef" value="true" />
<property name="expectedType" value="javax.sql.DataSource"/>
Try creating META-INF/aop.xml file as described in the following post: Why aspect j can't weave show Xlint cantFindType and exclude the com.ibm.ws.rsadapter.jdbc.* classes or better yet, include only your application classes.
I do have enough theory as to why, but this is how I fundamentally how to fix my issue:
Originally, in my Spring XML schema configuration, I had the following:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/mydatasource" />
But I had to convert it to the following:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/mydatasource" />
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>
So essentially as suggested I had to enforce this configuration change which added the following properties:
<property name="proxyInterface" value="javax.sql.DataSource"
Hopefully that help someone else out there
Thanks

persistence.xml property values from properties file

I have below configuration for entityManger
<jee:jndi-lookup id="dataSource" expected-type="javax.sql.DataSource"
jndi-name="java:jboss/datasources/AppDS"/>
<jee:jndi-lookup id="entityManagerFactory"
expected-type="javax.persistence.EntityManagerFactory"
jndi-name="java:comp/env/persistence/appPersistenceUnit"/>
I also have persistence.xml file, now I want to add hibernate-search feature to my application, so I have added below properties in my persistence.xml file ..
<property name="hibernate.search.default.directory_provider" value="filesystem" />
<property name="hibernate.search.default.indexBase" value="/var/lucene/indexes" />
Here I want to externalize indexBase property value to properties file, something like this.
<property name="hibernate.search.default.indexBase" value="${index.location}" />
Can any please suggest how I can achieve this ?
I am using Spring version : 4.
Thanks.
Update - 2
I have added below code to my application-context.xml
Commented this
<jee:jndi-lookup id="entityManagerFactory"
expected-type="javax.persistence.EntityManagerFactory"
jndi-name="java:comp/env/persistence/appPersistenceUnit"/>
and added below bean configuration ..
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>
</props>
</property>
</bean>
But after server restart it give below exception.. but if i keep same property in persistence.xml it works fine ..
Exception: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/D:/App/Projects/Projects/wildfly/bin/content/app.war/WEB-INF/classes/META-INF/spring/appContext-web.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unabl
e to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) [spring-beans-4.0.1.R
ELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) [spring-beans-4.0.1.RELE
ASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) [spring-beans-4.0.1.RELEAS
E.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) [spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) [spring-beans-4.0.1.RELEASE.jar:4.0.
1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) [spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) [spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973) [spring-context-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750) [spring-context-4.0.1.RELEA
SE.jar:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) [spring-context-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:187) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:86)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:71)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:233) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:272) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [hibernate-entitymanager-4.3.1.Final.jar:4.
3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.1.Final.jar:4.
3.1.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.
Final]
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150) [hibernate-entitymanager-4.3.1.Final.
jar:4.3.1.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336) [spring-or
m-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) [spring-orm-4.0.1.RELEASE.jar:4.0.1.
RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) [spring-beans-4.0.
1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) [spring-beans-4.0.1.R
ELEASE.jar:4.0.1.RELEASE]
... 21 more
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is
not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level c
ache provider (hibernate-infinispan, e.g.) is available on the classpath.
at org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:105) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cache.spi.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:73) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:72) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91) [hibernate-core-4.3.1.Final.jar:4.3
.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
... 34 more
18:14:59,612 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./app: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./app: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/
D:/Projects/wildfly/bin/content/app.war/WEB-INF/classes/META-INF/spring/appContext-web.xml]: Invocation of ini
t method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:216)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:86)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:71)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/D:/Pro
jects/wildfly/bin/content/app.war/WEB-INF/classes/META-INF/spring/appContext-web.xml]: Invocation of init method failed; nested exce
ption is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:187)
... 7 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:272)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 21 more
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is
not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level c
ache provider (hibernate-infinispan, e.g.) is available on the classpath.
at org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:105)
at org.hibernate.cache.spi.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:73)
at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:72)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223)
... 34 more
Also, i wanted to check what is the use of configLocation in LocalContainerEntityManagerFactoryBean ?
Thanks.
Update - 3
Sorry, I didn't provide full information, in my existing persistence.xml file
hibernate.cache.use_second_level_cache was already set to true, and it was working fine.
But in next requirement I had to implement search feature, so I used hibernate-search. And I have added hibernate.search.default.indexBase and hibernate.search.default.directory_provider in persistence.xml, after that it's working fine. It created index when entity is checked in, also updates index when entity is updated..
As I have to deploy this code on different environment, i have to specify different location for each environment. For all environments i have different properties files. So i want to do same for this hibernate.search.default.indexBase as well.. but after adding implementation as you suggested, still its not working ..
let me know if I can help you with any other information to find out solution ...
Update - 4
Below is my persistence.xml file ..
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="appPersistenceUnit"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/AppDS</jta-data-source>
<class>com.app.domain.User</class>
<!-- Other entity classes -->
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="jboss.entity.manager.factory.jndi.name"
value="persistence-units/appPersistenceUnit"/>
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
<!-- Disable transaction auto commit (production) -->
<property name="hibernate.connection.autocommit" value="false"/>
<!-- Default character set -->
<property name="hibernate.connection.charSet" value="UTF-8"/>
<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class"
value="jta"/>
<!-- SQL dialect -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<!-- Naming strategy -->
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<!-- Format SQL outpout -->
<property name="hibernate.format_sql" value="false"/>
<!-- Enabling Statistics -->
<property name="hibernate.generate_statistics" value="false"/>
<!-- value="create" to build a new database on each run; value="update"
to modify an existing database; value="create-drop" means the same as "create"
but also drops tables when Hibernate closes; value="validate" makes no changes
to the database -->
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<!-- Enable batch procession using an integer between 10-50 -->
<property name="hibernate.jdbc.batch_size" value="40"/>
<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql" value="false"/>
<!-- Envers -->
<property name="org.hibernate.envers.audit_strategy"
value="org.hibernate.envers.strategy.ValidityAuditStrategy"/>
<property
name="org.hibernate.envers.audit_strategy_validity_end_rev_field_name"
value="revision_end"/>
<property
name="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp"
value="true"/>
<property
name="org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name"
value="revision_end_time"/>
<property name="org.hibernate.envers.audit_table_suffix" value="_aud"/>
<property name="org.hibernate.envers.revision_field_name" value="revision"/>
<property name="org.hibernate.envers.revision_type_field_name" value="revision_type"/>
<property name="org.hibernate.envers.revision_listener"
value="com.app.listener.revision.RevisionListenerImpl"/>
<!-- Infinispan -->
<!-- Enables the query cache. You still need to set individual queries
to be cacheable. Call org.hibernate.Query.setCacheable(true) to initiate. -->
<property name="hibernate.cache.use_query_cache" value="true"/>
<!-- Enable second level cache. Requires session flushing. -->
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<!-- Hibernate Search properties -->
<property name="hibernate.search.default.directory_provider" value="filesystem" />
<property name="hibernate.search.default.indexBase" value="/var/lucene/indexes" />
</properties>
</persistence-unit>
</persistence>
and, below is my spring configuration file, also i have added <bean> configuration which i tried after your inputs, which is commented below jee:jndi-lookup
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd">
<jee:jndi-lookup id="dataSource" expected-type="javax.sql.DataSource"
jndi-name="java:jboss/datasources/AppDS"/>
<jee:jndi-lookup id="entityManagerFactory"
expected-type="javax.persistence.EntityManagerFactory"
jndi-name="java:comp/env/persistence/appPersistenceUnit"/>
<!-------------------------
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>
</props>
</property>
</bean>
-->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"/>
<bean id="entityManager"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="exceptionTranslator"
class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
</beans>
Let me know if you want me to add any other details . .
Thanks ..
Since the persistence.xml lies outside the spring it isn't possible to inject properties via spring property placeholder.
The inherited method setJpaProperties of Springs' LocalContainerEntityManagerFactoryBean will solve the purpose you are looking forward too.
Sample spring bean configuration would look something like below -
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.search.default.indexBase">${index.location}</prop>
</props>
</property>
Note that this will still read the configuration from persistence.xml with additional facilities. (e.g. customized location for persistence.xml instead of default META-INF)

Spring WorkManagerTaskExecutor cannot initialize in websphere

i want use Websphere work manager for executing async jobs in jee context but i have problem with creating spring WorkManager.
bean definition:
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor"> <property name="workManagerName" value="wm/default" /> </bean>
this definition i found in websphere help. But problem is this ends with noClassDefFound. I noticed pckg org.springframework.scheduling.commonj is missing from spring-context since version 2.x.x
Is it replaced with org.springframework.jca.work.WorkManagerTaskExecutor ?
when i use this other spring class, i get error:
Caused by: org.springframework.jndi.TypeMismatchNamingException:
Object of type [class com.ibm.ws.asynchbeans.WorkManagerImpl]
available at JNDI location [wm/default] is not assignable to
[javax.resource.spi.work.WorkManager]
so whats deal here? thx
was - 7.0.0.23
spring - 3.1.2
Class org.springframework.scheduling.commonj.WorkManagerTaskExecutor resides in spring-context-support-3.1.2.RELEASE.jar
Configuration succeeds with javax.resource.spi.work.WorkManager in applicationContext-service.xml in deployment.....
In my case deployment fails for bean injection org.springframework.scheduling.commonj.WorkManagerTaskExecutor as it fails to take WorkManager JNDI Configured in Application Server.... I just replaced javax.resource.spi.work.WorkManager. And so far it is success deployment.
I yet to see application works fine with it.
<bean id="taskExecutor" class="javax.resource.spi.work.WorkManager">
<property name="workManagerName" value="wm/default" />
</bean>
In our scenario we were managed it by ThreadPoolTaskExecutor instead of WorkManagerTaskExecutor
Here is configuration that comes in ApplicationContext.xml
<!--
<bean id="rtSenderTaskExecutor"
class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName">
<value>${org.quartz.threadPool.jndi}</value>
</property>
</bean> -->
<!-- Local Thread Pool -->
<bean id="rtSenderTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="${org.quartz.threadPool.corePoolSize}" />
<property name="maxPoolSize" value="${org.quartz.threadPool.maxPoolSize}" />
<property name="queueCapacity" value="${org.quartz.threadPool.queueCapacity}" />
<property name="keepAliveSeconds" value="${org.quartz.threadPool.keepAliveSeconds}"></property>
</bean>

How to change Spring to use Datasource from Tomcat vs BasicDataSource?

How to change Spring to use Datasource from Tomcat vs BasicDataSource? below is a copy of the bean I make in my XML. Can someone tell me how to access the tomcat datasource
<beans:bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" >
<beans:property
name="driverClassName"
value="${database.driver}" />
<beans:property
name="url"
value="${database.url}" />
<beans:property
name="username"
value="${database.user}" />
<beans:property
name="password"
value="${database.password}" />
<beans:property
name="initialSize"
value="5" />
<beans:property
name="maxActive"
value="10" />
</beans:bean>
In spring you have to change the configuration that it takes the configuration from tomcat via JNDI
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/myNewDatasource" />
</beans>
Then you have to configure the connection within tomact and make it available though jndi.
For example you could put this in the tomcat context.xml (and of course you need to put the driver in the tomcat lib directory)
<Resource name="jdbc/myNewDatasource"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://SERVER:3306/DB?useUnicode=true&characterEncoding=utf8"
auth="Container" username="USERNAME" password="PASSWORD"
maxIdle="3" maxActive="15" maxWait="10000"
logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="60"
validationQuery="select 1" />

Resources