Velocity Engine is being used in my project for sending mails on user action and on job trigger.
While the mails that are sent on user action are perfectly fine, The mails being sent by jobs are sometimes received with empty content. This is very random and i cannot seem to connect it with any cause. There are no Error logs when this happens. (I did get a Velocity could not be initialized error once, before adding the NullLogChute property. I was advised that this would solve the exception, but all it did was to stop the exception from coming up in the logs. mails still have empty content) Please help!
Earlier exception:
ERROR 2012-07-29 05:00:00,219 com.myProject.util.VelocityUtil - Velocity could not be initialized!
java.lang.RuntimeException: Velocity could not be initialized!
..
..
Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.AvalonLogChute with the current runtime configuration.
I am setting the velocity config properties in my spring servlet xml :
<bean id="velocityUtil" class="com.myProject.util.VelocityUtil" >
<property name="velocityConfiguration">
<props>
<prop key="resource.loader">class</prop>
<prop key="class.resource.loader.class">org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</prop>
<prop key="runtime.log.logsystem.class">org.apache.velocity.runtime.log.NullLogChute</prop>
</props>
</property>
Quartz properties set in spring servlet:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey"><value>applicationContext</value></property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">Quartz</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.rmi.export">false</prop>
<prop key="org.quartz.scheduler.rmi.proxy">false</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">5</prop>
<prop key="org.quartz.threadPool.threadPriority">1</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.tablePrefix">EES.QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.MSSQLDelegate</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="triggers">
<list>
<ref bean="Mod1CronTrigger" />
<ref bean="Mod2CronTrigger" />
<ref bean="Mod3CronTrigger" />
<ref bean="Mod4CronTrigger" />
<ref bean="Mod5CronTrigger" />
<ref bean="Mod6CronTrigger" />
</list>
</property>
</bean>
Each of the triggers in the <list> define the jobDetail and CronExpression. for example,
<bean id="Mod1CronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="Mod1Job"/>
<property name="cronExpression" value="0 30 3 1/1 * ? *"/>
</bean>
and
<bean name="Mod1Job" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myProject.jobs.Mod1Job" />
<property name="name" value="Mod1Job" />
</bean>
Related
Trying to connect two different datasources with the Atomikos transaction manager getting the below error
Caused by: java.lang.ClassCastException: com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory cannot be cast to org.hibernate.resource.transaction.TransactionCoordinatorBuilder
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:Application.properties" />
</bean>
<bean id="oracleSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="oraclesDataSource" />
<property name="mappingResources">
<list>
<value>persons.hbm.xml </value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<!-- <prop key="hibernate.autocommit">true</prop>
<prop key="hibernate.connection.isolation">3</prop> -->
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.transaction.factory_class">
com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
</prop>
<prop key="hibernate.transaction.manager_lookup_class">
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
</prop>
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
</props>
</property>
</bean>
<bean id="mysqlSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="mysqlDataSource" />
<property name="mappingResources">
<list>
<value>persons.hbm.xml </value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- <prop key="hibernate.autocommit">ture</prop>
<prop key="hibernate.connection.isolation">3</prop> -->
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.transaction.factory_class">
com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
</prop>
<prop key="hibernate.transaction.manager_lookup_class">
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
</prop>
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
</props>
</property>
</bean>
<tx:annotation-driven proxy-target-class="true" />
<tx:jta-transaction-manager
transaction-manager="atomikosTransactionManager" />
<tx:annotation-driven transaction-manager="atomikosTransactionManager"
proxy-target-class="true" />
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="false" />
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
<property name="transactionTimeout" value="300" />
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
depends-on="atomikosTransactionManager,atomikosUserTransaction">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="atomikosUserTransaction" />
<!-- <property name="allowCustomIsolationLevels" value="true" /> -->
</bean>
<bean id="mysqlDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>mySqlDataSource</value>
</property>
<property name="xaDataSourceClassName">
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="databaseName">sys</prop>
<prop key="serverName">localhost</prop>
<prop key="port">3306</prop>
<prop key="user">root</prop>
<prop key="password">magesh123</prop>
<prop key="url">jdbc:mysql://localhost:3306/sys</prop>
</props>
</property>
<property name="minPoolSize">
<value>1</value>
</property>
</bean>
<bean id="oraclesDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>OracleDataSource</value>
</property>
<property name="xaDataSourceClassName">
<value>oracle.jdbc.xa.client.OracleXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="databaseName">XE</prop>
<prop key="serverName">localhost</prop>
<!-- <prop key="port">1521</prop> -->
<prop key="user">system</prop>
<prop key="password">magesh123</prop>
<prop key="URL">jdbc:oracle:thin:#localhost:1521:XE</prop>
</props>
</property>
<property name="minPoolSize">
<value>1</value>
</property>
</bean>
<bean id="persons" class="com.bnym.aal.poc.spring_jta.Persons">
</bean>
<bean id="App" class="com.bnym.aal.poc.spring_jta.App">
<property name="springJtaDaoClass" ref="springJtaDaoClass" />
</bean>
<bean id="springJtaDaoClass" class="com.bnym.aal.poc.spring_jta.springJtaDaoClass">
<property name="oracleSessionFactory" ref="oracleSessionFactory" />
<property name="mysqlSessionFactory" ref="mysqlSessionFactory" />
<property name="atomikosTransactionManager" ref="transactionManager" />
<property name="persons" ref="persons" />
</bean>
Changed my hibernate transaction manager to below one and the Transaction manager worked
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.CMTTransactionFactory
</prop>
Please refer to the below Git url for the POC on the Atomikos transaction manager for the out of box integration of the Spring - JTA
https://github.com/mageshsrinivasulu/spring-jta.git
Is there a way to provide another value for key if null? I want to use the source and dest db. But if dest db details are null then use source.
<bean id="dataSource" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="springHikariCP" />
<property name="dataSourceClassName" value="oracle.jdbc.pool.OracleDataSource" />
<property name="maximumPoolSize" value="${maximumPoolSize}" />
<property name="idleTimeout" value="${idleTimeout}" />
<property name="connectionTimeout" value="${connectionTimeout}" />
<property name="dataSourceProperties">
<props>
<prop key="url">${dest.db.url}</prop>
<prop key="user">${dest.db.user}</prop>
<prop key="password">${dest.db.password}</prop>
</props>
</property>
</bean>
What I tried:
<property name="dataSourceProperties">
<props>
<prop key="url">${dest.db.url?:${src.db.url}}</prop>
<prop key="user">${dest.db.user?:${src.db.user}}</prop>
<prop key="password">${dest.db.password?:${src.db.password}}</prop>
</props>
</property>
</bean>
Though the dest db details are not null, the data is being written into the source. Not sure why? Is there something wrong in the way I'm defining it?
You can use ternary operator to specify an if-else condition in spel. Take a look at this:
http://www.mkyong.com/spring3/spring-el-ternary-operator-if-then-else-example/
I am getting following Error, for my spring ioc container definition. It basically has a Spring Quartz Scheduler Bean Definition.
This is the final root cause of the error.
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'scrService': org.springframework.beans.factory.FactoryBeanNotInitializedException: FactoryBean is not fully initialized yet
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:170) [spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:126) [spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1467) [spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246) [spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) [spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) [spring-beans-3.2.13.RELEASE.jar:3.2.13.RELEASE]
... 114 more
Here is ApplicationContext-beans.xml configuration
<bean id="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
destroy-method="destroy">
<property name="schedulerName">
<value>${org.quartz.scheduler.instanceName}</value>
</property>
<property name="autoStartup" value="true" />
<property name="startupDelay" value="10" />
<!-- To prevent picking up jobs from the database, please remove the line below -->
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager"/>
<property name="taskExecutor" ref="senderTaskExecutor" />
<property name="waitForJobsToCompleteOnShutdown" value="true"></property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceId">
${org.quartz.scheduler.instanceId}
</prop>
<!-- add key="org.quartz.jobStore.class" with value "org.quartz.simpl.RAMJobStore" for an in memory scheduler -->
<!-- Remove the 3 lines below for an in memory scheduler -->
<prop key="org.quartz.jobStore.driverDelegateClass">
${org.quartz.jobStore.driverDelegateClass}
</prop>
<prop key="org.quartz.jobStore.isClustered">
${org.quartz.jobStore.isClustered}
</prop>
<prop
key="org.quartz.jobStore.clusterCheckinInterval">
${org.quartz.jobStore.clusterCheckinInterval}
</prop>
<prop key="org.quartz.jobStore.useProperties">
${org.quartz.jobStore.useProperties}
</prop>
</props>
</property>
<property name="schedulerContextAsMap">
<map>
<!--<entry key="scrService">
<ref bean="scrService" />
</entry>-->
<entry key="numberLevelService">
<ref bean="numberLevelService" />
</entry>
<!--
...
-->
</map>
</property>
</bean>
<!--
...
-->
<bean id="scrService" parent="baseServiceTransactionProxy">
<property name="target" ref="scrServiceTarget"></property>
</bean> <!--abstract does not have Impl associated for scrServiceTarget or some problem-->
<bean id="numberLevelService" class="com.ding.dong.NumberLevelControllerImpl" factory-method="getInstance" lazy-init="true">
<constructor-arg ref="dataSource"></constructor-arg>
</bean>
<bean id="scrServiceTarget"
class="com.ding.dong.scrServiceImpl">
<property name="pageSizeFactor">
<value>${service.sender.pageSizeFactor}</value>
</property>
<property name="tpsFactor">
<value>${service.sender.tpsFactor}</value>
</property>
<property name="scrDao" ref="scrDao"></property>
<property name="scrRuntimeDao" ref="scrRuntimeDao"></property>
<property name="scrReportDao" ref="scrReportDao"></property>
<property name="scrTemplateDao"
ref="scrTemplateDao">
</property>
<property name="schedulerService" ref="schedulerService"></property>
<property name="shortCodeManagerService"
ref="shortCodeManagerService">
</property>
<property name="userRoleService" ref="userRoleService"></property>
<!-- To prevent connecting to JMS, please remove the line below -->
<property name="messageSenderService"
ref="messageSenderService">
</property>
</bean>
<bean id="baseServiceTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="scheduleSCR">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="removeScheduledSCR">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="extendInProgressSCR">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="stopInProgressSCR">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="retrieveSCRForExecution">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="updateSCRState">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="process*">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="updateMessageLogForContestWinners">
PROPAGATION_REQUIRED,-SCRServiceRuntimeException
</prop>
<prop key="retrieveSCR">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="retrieveTemplate">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="getScheduledSCRsMessageCount">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="isUserQuotaExceeded">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="retrieveActiveSCR*">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="retrieveSCRInfo">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="scheduleTask">
PROPAGATION_REQUIRED,-SchedulerServiceRuntimeException
</prop>
<prop key="*ScheduledTask">
PROPAGATION_REQUIRED,-SchedulerServiceRuntimeException
</prop>
<prop key="updateTaskSchedule">
PROPAGATION_REQUIRED,-SchedulerServiceRuntimeException
</prop>
</props>
</property>
<property name="preInterceptors">
<ref bean="performanceInterceptor" />
</property>
</bean>
For now I had commented the following Quartz Scheduler Entry, So it works fine...
<!--<entry key="scrService">
<ref bean="scrService" />
</entry>-->
As per my interpretation of trace-log, scrService has abstract implementation...
Please advise about this situation... Thanks for your suggestions....
I've been looking for days now for a simple implementation of Spring batch processor with the scheduler (Quartz) but with no luck! all the samples that i laid my hands on were not working or depreciated, my application should provide setting the job firing time dynamically (retrieved from Database)
try adding below code in spring-quartz.xml file
<!--testAlerts cron trigger -->
<bean id="testAlertsTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="name" value="testAlertsTrigger" />
<property name="jobDetail" ref="testAlertsJobDetail" />
<property name="cronExpression" value="0 0 4 * * ?" />
</bean>
<!-- scheduler -->
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="hbnTransactionManager" />
<property name="triggers">
<list>
<ref bean="testAlertsTrigger" />
</list>
</property>
<property name="schedulerContextAsMap">
<map>
<entry key="commandDispatcher" value-ref="commandDispatcher" />
</map>
</property>
<property name="autoStartup" value="${QUARTZ.org.quartz.autoStartup}" />
<property name="overwriteExistingJobs" value="${QUARTZ.org.quartz.overwriteExistingJobs}" />
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceId">${QUARTZ.org.quartz.scheduler.instanceId}</prop>
<prop key="org.quartz.scheduler.instanceName">${QUARTZ.org.quartz.scheduler.instanceName}</prop>
<prop key="org.quartz.threadPool.threadCount">${QUARTZ.org.quartz.threadPool.threadCount}</prop>
<prop key="org.quartz.jobStore.class">${QUARTZ.org.quartz.jobStore.class}</prop>
<prop key="org.quartz.jobStore.isClustered">${QUARTZ.org.quartz.jobStore.isClustered}</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">${QUARTZ.org.quartz.jobStore.clusterCheckinInterval}</prop>
</props>
</property>
</bean>
How can I integrate OSworkflow with spring and hibernate.What are the configuration i need to specify in xml files and which jar files are requires for it.
Update
I have defined the applicationContext.xml as follows
<bean id="workflowStore" class="com.opensymphony.workflow.spi.hibernate.SpringHibernateWorkflowStore" autowire="byName"> <property name="resource" value="workflow-defs.xml"/>
<property name="reload" value="true"/> </bean>
<bean id="workflowFactory" class="com.opensymphony.workflow.loader.XMLWorkflowFactory" init-method="initDone"/>
<bean id="workflowConfiguration" class="com.opensymphony.workflow.config.SpringConfiguration">
<property name="store"><ref local="workflowStore"/></property>
<property name="factory"><ref local="workflowFactory"/></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="packagesToScan" value="net.top.*.entity.*" />
<property name="mappingResources">
<list>
<value>com/opensymphony/workflow/spi/hibernate/WorkflowDescriptor.hbm.xml</value>
<value>com/opensymphony/workflow/spi/hibernate/HibernateCurrentStep.hbm.xml</value>
<value>com/opensymphony/workflow/spi/hibernate/HibernateHistoryStep.hbm.xml</value>
<value>com/opensymphony/workflow/spi/hibernate/HibernateWorkflowEntry.hbm.xml</value>
<value>com/opensymphony/module/propertyset/hibernate/PropertySetItemImpl.hbm.xml</value>
</list>
</property>
</bean>
It shows an error as
Could not determine type for: com.opensymphony.workflow.loader.NotNullStringType, for columns: [org.hibernate.mapping.Column(value)]
Did i miss anything?.