ReloadingPropertyPlaceholderConfigurer - java

For some reason the ReloadablePropertiesFactoryBean doens't seem to do what I expect. When I change a property in the test.properties file I get a log message saying:
9979 [timer] INFO com.krest.core.properties.ReloadablePropertiesFactoryBean - Reloading Properties...
But for some reason nothing happens. The old property value is still set on my test bean. Does anybody know why this is? I use Spring 3 and my configuration looks like this:
<bean id="configproperties"
class="com.krest.core.properties.ReloadablePropertiesFactoryBean">
<property name="location"
value="classpath:test.properties" />
</bean>
<bean id="propertyConfigurer"
class="com.krest.core.properties.ReloadingPropertyPlaceholderConfigurer">
<property name="properties" ref="configproperties" />
<property name="reloadingPlaceholderPrefix" value="rel{" />
<property name="reloadingPlaceholderSuffix" value="}" />
</bean>
<bean id="mybean" class="nl.mycompany.TestBean">
<property name="message" value="rel{timer-delay}" />
</bean>
<!-- regularly reload property files. -->
<bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<bean id="reloadProperties"
class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="period" value="1000" />
<property name="runnable">
<bean class="com.krest.core.properties.ReloadConfiguration">
<property name="reconfigurableBeans">
<list>
<ref bean="configproperties" />
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>

Related

Spring-orm 5x version

Currently, I am converting the spring-orm 3x version to 5x. and Hibenate 3x to 5x. My applicationcontext.xml file have a configuration
<property name="typeDefinitions">
<list>
<bean
class="org.springframework.orm.hibernate3.TypeDefinitionBean">
<property name="typeName" value="varchar_enum" />
<property name="typeClass"
value="xxx.xxx.xxx" />
</bean>
<bean
class="org.springframework.orm.hibernate3.TypeDefinitionBean">
<property name="typeName" value="trimmed_string" />
<property name="typeClass"
value="xxx.xxx.xxx" />
</bean>
</list>
</property>

Camel-Mybatis Open session Exception

I'm using Camel-Mybatis version 2.12.0.redhat-610379, when we trying to start the bundle thru karaf container the following exception throws. Please advice.
org.apache.ibatis.exceptions.PersistenceException:
Error opening session. Cause: java.lang.NullPointerException
Cause: java.lang.NullPointerException
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)[280:org.mybatis.mybatis:3.2.5]
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:88)[280:org.mybatis.mybatis:3.2.5]
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:43)[280:org.mybatis.mybatis:3.2.5]
at org.apache.camel.component.mybatis.MyBatisProducer.process(MyBatisProducer.java:51)[282:org.apache.camel.camel-mybatis:2.12.0.redhat-611412]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:279)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:56)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:166)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.processByErrorHandler(TransactionErrorHandler.java:218)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:99)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.processByErrorHandler(TransactionErrorHandler.java:218)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler$1.doInTransactionWithoutResult(TransactionErrorHandler.java:181)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)[149:org.apache.servicemix.bundles.spring-tx:3.2.9.RELEASE_1]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)[149:org.apache.servicemix.bundles.spring-tx:3.2.9.RELEASE_1]
at org.apache.camel.spring.spi.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:174)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:134)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:103)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:147)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:69)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at java.util.TimerThread.mainLoop(Timer.java:555)[:1.7.0_01]
at java.util.TimerThread.run(Timer.java:505)[:1.7.0_01]
Caused by: java.lang.NullPointerException
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:83)[280:org.mybatis.mybatis:3.2.5]
... 32 more
Bean.xml
<bean id="ds" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="jdbcUrl" value=""/>
<property name="user" value=""/>
<property name="password" value="" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<argument ref="ds" />
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="mybatisConfig" class="org.springframework.core.io.ClassPathResource">
<argument value="SqlMapConfig.xml" />
</bean>
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" ref="mybatisConfig"/>
<property name="mapperLocations">
<array value-type="org.springframework.core.io.Resource">
<bean class="org.springframework.core.io.ClassPathResource">
<argument value="mappings/QueryMessaging.xml" />
</bean>
</array>
</property>
</bean>
<bean id="sqlSessionFactory" class="org.apache.ibatis.session.SqlSessionFactory" factory-ref="sqlSessionFactoryBean"
factory-method="getObject" />
<bean id="myBatis" class="org.apache.camel.component.mybatis.MyBatisComponent">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="txManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>
Connections and configurations are created properly, the bug I have made was in bean.xml i have used myBatis bean id, and camel route i have type as mybatis, due to case-sensitive, no environment was created, sorry for that.

Loading multiple external properties files from spring

I want to load all the properties files with Spring from an external folder. I successfully load one file but adding a wildcard to the mix does not seem to work.
This works (load test.properties):
<bean id="propertiesLocation"
class="org.springframework.web.context.support.ServletContextParameterFactoryBean">
<property name="initParamName"><value>file://EXTERNAL_DIRECTORY/test.properties</value></property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" ref="propertiesLocation"></property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="0"/>
</bean>
This does not (load *.properties):
<bean id="propertiesLocation"
class="org.springframework.web.context.support.ServletContextParameterFactoryBean">
<property name="initParamName"><value>file://EXTERNAL_DIRECTORY/*.properties</value></property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" ref="propertiesLocation"></property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="0"/>
</bean>
The error:
Caused by: java.io.FileNotFoundException: /EXTERNAL_DIRECTORY/*.properties (No es un directorio)
How can I make Spring load all the external properties files in a folder?
Edit: I use the first bean (ServletContextParameterFactoryBean) because in the project I retrieve the path from the web.xml file. I forgot about this and just pasted the path in the bean, it is incorrect but has nothing to do with the question.
Try use following:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="file://EXTERNAL_DIRECTORY/*.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="0"/>
</bean>
If you need include more resources you can do next:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" >
<list>
<value>classpath:single.properties"</value>
<value>file://EXTERNAL_DIRECTORY/*.properties"</value>
<value>file://ANOTHER_EXTERNAL_DIRECTORY/*.properties"</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="0"/>
</bean>
With default implementation of PropertyEditor, Spring will convert strings into Resource. You can find details in documentation.
Hope this will be helpful.

ActiveMQ Data persistent Issue in Java Spring

I have an application which uses embedded activeMQ 5.11. At the start of the application it creates activemq-data\producerBroker\KahaDB folder at the class path location. I do want to change the location but spring.xml doesn't take a location.
Spring.xml as given,
<bean id="producerBroker" class="org.apache.activemq.broker.SslBrokerService">
<property name="brokerName" value="producerBroker" />
<property name="persistent" value="true" />
<property name="persistenceAdapter" ref="persistenceAdapter"/>
<property name="transportConnectors">
<list>
<bean class="org.apache.activemq.broker.TransportConnector">
<property name="name" value="xxx"></property>
<property name="uri" value="${transportConnectorURIs}"></property>
</bean>
</list>
</property>
<property name="jmsBridgeConnectors">
<list>
<bean class="org.apache.activemq.network.jms.JmsQueueConnector">
<property name="outboundQueueConnectionFactory">
<bean class="org.apache.activemq.ActiveMQSslConnectionFactory">
<property name="brokerURL" value="${brokerURL}" />
<property name="userName" value="${username}" />
<property name="password" value="${password}" />
<property name="trustStore" value="${trust.store.path}" />
<property name="trustStorePassword" value="${trust.store.password}" />
<!-- <property name="keyStore" value="${key.store.path}"/> -->
<!-- <property name="keyStorePassword" value="${key.store.password}"/> -->
</bean>
</property>
<property name="outboundQueueBridges">
<list>
<bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
<constructor-arg value="${screenshotQueueName}" />
</bean>
<bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
<constructor-arg value="${resultXmlQueueName}" />
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
<bean id="persistenceAdapter" class="org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter">
<property name="directory" value="E:\test"/>
Current issue is it throws an error as "exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.activemq.store.kahadaptor.KahaPersistenceA
apter] for bean with name 'kahaPersistenceAdapter' defined in class path resource [spring/resultupload/resultupload.xml]; nested exception is java.la
g.ClassNotFoundException: org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter"
Anyone has experience in the directory change in activeMQ 5.11 in java spring?
The destination of the persistence location must be defined at the broker level.
The kahaPersistenceAdapter (which was file based) was removed with version 5.9. You should use the kahaDB.
kahaDB - uses KahaDB an embedded lightweight non-relational database
<broker brokerName="broker" persistent="true" useShutdownHook="false">
<transportConnectors>
<transportConnector uri="tcp://localhost:61616"/>
</transportConnectors>
<persistenceAdapter>
<kahaDB directory="e:/temp" ... />
</persistenceAdapter>
</broker>
all valid attributes: http://activemq.apache.org/schema/core/activemq-core-5.11.0-schema.html#kahaDB

method-invoking Spring bean

I've declared the following bean in my Spring config
<bean id="templateCacheClearingTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="delay" value="5000" />
<property name="period" value="5000" />
<property name="timerTask">
<bean class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
<property name="targetObject" ref="templateMailService" />
<property name="targetMethod" value="clearCache" />
</bean>
</property>
</bean>
This should cause the clearCache() method of the templateMailService bean to be invoked every 5000ms, but nothing appears to be happening. Am I missing something?
Cheers,
Don
I think you need:
<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref bean="templateCacheClearingTask"/>
</list>
</property>
</bean>
In addition to what you already have.

Categories