I'am using Mule CE 3.3.0 and I have a problem with the PropertyPlaceHolder's scope. Let's suppose that I have two mule application (writeApp and readApp). In the writeApp application I set a propertyPlaceholer bean as defined below:
<spring:bean id="consignmentProperty" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<spring:property name="ignoreUnresolvablePlaceholders" value="true"/>
<spring:property name="locations">
<spring:list>
<spring:value>classpath:connections.properties</spring:value>
<spring:value>.....</spring:value>
</spring:list>
</spring:property>
</spring:bean>
And in the readApp application I try to read the property defined in the writeApp
<mule>
<flow name="readContextVariableFlow1" doc:name="readContextVariableFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8085" path="read" doc:name="HTTP"/>
<append-string-transformer message="${prop.conn}" doc:name="Append String"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
</mule>
The problem is that right now I'am able to read the prop.conn property from readApp, although it is defined in the writeApp. I would able to define a specific file property for each application.
Thank you in advance for any kind of help
You could namespace your properties to prevent cross-sharing, like "readApp.prop.conn" and "writeApp.prop.conn".
Alternatively, try turning system properties off:
<spring:beans>
<context:property-placeholder location="classpath:connections.properties"
ignore-unresolvable="true" system-properties-mode="NEVER" />
</spring:beans>
Related
I have the following defined in XML configuration:
<task:scheduler id="myScheduler" pool-size="10" />
<bean id="asyncExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
<bean id="asyncExecutor2" class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
When using the #Async annotation in Spring, how does it know which of these executors/schedulers to use? I would expect it to throw an error on startup since there are multiple here and I have not included a <task:annotation-driven executor="xxx"/> tag, but it appears to be working fine. Is there a way I can log somewhere which one is being used?
...
<task:annotation-driven executor="asyncExecutor" />
<task:executor id="asyncExecutor" pool-size="10" />
...
You might look at the thread name in the stacktrace when debugging, it should start with something like: [asyncExecutor-xx]
I have an application in Spring with is using RabbitMQ. I'm using xml based context configuration and rabbit namespace in this xml.
So far it looked as this:
<rabbit:connection-factory id="rabbitConnectionFactory" host="localhost" port="5672"/>
but now I want to use JNDI variables for host and port properties.
I know how to use JNDI when I have "classic" bean definitions but I have know idea how to use JNDI and rabbit namespace at the same time.
I wasn't able to define any child elements of rabbit:connection element. I get an error saying that it can't have any child nodes.
Any help appreciated :)
EDIT
This is how I use JNDI lookup in "standard" beans (with no special namespace)
<bean id="connector" class="com.foo.ConnectionProvider">
<constructor-arg name="url">
<jee:jndi-lookup expected-type="java.lang.String" jndi-name="java:comp/env/service/url"/>
</constructor-arg>
</bean>
And in META-INF/context.xml:
<ResourceLink name="service/url" global="service/url" type="java.lang.String"/>
But as I said I don't know how to accomplish it using rabbit namespace. Have tried googling with no success..
I figured out I can use "standard" bean definition. I'm not completely happy with the solution, but at least, it works.
<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<constructor-arg name="hostname" >
<jee:jndi-lookup expected-type="java.lang.String"
jndi-name="java:comp/env/rabbit/host"/>
</constructor-arg>
<constructor-arg name="port" >
<jee:jndi-lookup expected-type="java.lang.Integer"
jndi-name="java:comp/env/rabbit/port"/>
</constructor-arg>
<property name="username" value="guest"/>
<property name="password" value="guest"/>
</bean>
<rabbit:template id="amqpTemplate" connection-factory="rabbitConnectionFactory" exchange="mcs-notifications.topic"/>
<rabbit:admin connection-factory="rabbitConnectionFactory"/>
Another option is to use RMQConnectionFactory
<Resource name="jms/rabbitConnectionFactory" type="com.rabbitmq.jms.admin.RMQConnectionFactory"
factory="org.apache.naming.factory.BeanFactory" username="guest"
password="guest" />
I need help to load/inject tomcat/conf/catalina/localhost/myapp.xml in my SpringJunit Test. I am testing my mail service from JUnit.
Mail Spring XML:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="#{contextParameters.mail_host}"/>
<property name="username" value="#{contextParameters.mail_username}" />
<property name="password" value="#{contextParameters.mail_password}" />
<property name="port" value="#{contextParameters.mail_port}" />
....
Tomcat MyApp.xml:
<Context reloadable="true">
<Parameter name="mail_host" value="XXXXX" override="true"/>
<Parameter name="mail_username" value="XXXXXX" override="true"/>
....
I need to inject my mail details from tomcat myapp.xml in spring-mail.xml. I can able to load my spring context properties and beans but not tomcat parameters. Help appreciated!.
Is it possible to specify the fixed delay interval or the cron interval pattern through some custom properties when deployed on web sphere. Currently, in my configuration the fixed delay interval is specified on the application context xml file. However, this file will get packaged in an EAR and a change to interval would require application redeployment.
Here is my app context file:
<bean id="taskScheduler" class="org.springframework.scheduling.commonj.TimerManagerTaskScheduler">
<property name="timerManager" ref="timerManager" />
</bean>
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManager" ref="workManager" />
</bean>
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ref="transactionProcessingService" method="processTransactions" fixed-delay="30000"/>
<task:scheduled ref="transactionProcessingService" method="processOrderTransactions" fixed-delay="50000"/>
</task:scheduled-tasks>
Thanks for your suggestions.
Add the following in your application context
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:sample.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="order" value="0"/>
</bean>
Your sample.properties file
process_transactions = 30000
processOrder_transactions = 3000
Replace the following with your code.
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ref="transactionProcessingService" method="processTransactions" fixed-delay="${process_transactions}"/>
<task:scheduled ref="transactionProcessingService" method="processOrderTransactions" fixed-delay="${processOrder_transactions}"/>
</task:scheduled-tasks>
You can use <util:properties /> tag for loading properties from files:
Move your values to some property file (for example app.properties)
process_transactions=30000
process_order_transactions=3000
load them via properties tag from util namespace (do not forget to declare util namespace)
<util:properties id="appConfig" location="classpath:app.properties" />
set them using ${variable}syntax:
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ... fixed-delay="${process_transactions}"/>
<task:scheduled ... fixed-delay="${process_order_transactions}"/>
</task:scheduled-tasks>
EDIT. As explained by #user320587 we can override application property value by using JVM Custom properties in Websphere (and avoid redeploiment):
By using this along with the systemPropertiesModeName property
available in the PropertyPlaceHolderConfigurer, we could avoid
redeployment. I have set the property values as part of JVM Custom
properties in Websphere and the substitution happens when the
application is started. So, to change the interval value, I can modify
the custom property value and restart the application.
I have the following spring config file:
<context:property-placeholder order="2"
ignore-unresolvable="true" ignore-resource-not-found="true"
location="file:///${user.home}/application.properties" />
<context:property-placeholder order="1"
ignore-unresolvable="true" ignore-resource-not-found="true"
location="file:///C:/Services/Tomcat 6.0/cms/application.properties" />
<context:property-placeholder order="3"
location="classpath:com/afrozaar/cms/service/application.properties" />
Notice how they are ordered, some are on the classpath and some are on the file system.
Now to the mix I want to add a properties file loaded via jndi. I was hoping to be able to do
<context:property-placeholder order="2"
ignore-unresolvable="true" ignore-resource-not-found="true"
location="jndi:url/application.properties" />
Unfortunately, this doesn't work, spring doesn't support the jndi prefix... AFAIK.
So, can I do something like this?
And if I can't what's my alternative. I don't want to have to convert my whole configuration to a full bean based property place holder configurer.
Not sure what you really mean with "jndi:url/application.properties". I suppose you wanted to set the path to the property file in a resource entry named "url/application.properties".
You can achieve this with the following snippets:
<bean class="org.springframework.beans.factory.config.PlaceholderConfigurerSupport">
<property name="location">
<bean id="publisherLocal" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="url/application.properties" />
<property name="expectedType" value="java.lang.String" />
</bean>
</property>
</bean>
<context:property-placeholder> has a properties-ref attribute, which can point to the bean of type Properties. So, you can load Properties in your code and declare a <context:property-placeholder> using them.