I have several flows in my mule-config.xml but some beans only makes sense to say one flow. Is there a way to define a bean local to a flow. I understand that I can define an inline bean like below:
<custom-transformer name="soapFaultTransformer" class="com.xxx.xx.transformer.VelocityMessageTransformer">
<spring:property name="velocityEngine" ref="velocityEngine" />
<spring:property name="templateName" value="soapFault.vm" />
<spring:property name="beanClass">
<spring:bean class="com.xxx.services.xx.Soap11Fault">
<spring:property name="faultCode" value="Client" />
<spring:property name="faultString" value="Invalid Request" />
<spring:property name="detail" value="..." />
</spring:bean>
</spring:property>
</custom-transformer>
but the inline spring bean is needed to use at 2 places in a single flow? Can I still define it in a single place and refer it in 2 places without making it global bean?
Thank you
How about gathering all the spring bean necessary for a single flow into a separate spring config file that is imported only by that flow?
Your mule config will look like the following:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<spring:import resource="encapsulated-beans.xml" />
<flow name="flow" >
...
</flow>
</mule>
where encapsulated-beans.xml will be the config file that includes, for example, your com.xxx.services.xx.Soap11Fault bean
As #David said, it's not possible to declare beans specific to a single flow. Declared beans will be available to all flows.
Related
I am getting the below error while deploying my application in Weblogic. The functionality was working fine with the older Spring version. After upgrading the spring from 2 to 4, we are getting this error :
java.lang.AbstractMethodError:
org.springframework.integration.config.xml.AbstractRouterParser.parseRouter(Lorg/w3c/dom/Element;Lorg/springframework/beans/factory/support/BeanDefinitionBuilder;Lorg/springframework/beans/factory/xml/ParserContext;)V
Below is the XML file content :
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-4.3.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-4.3.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream-4.3.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml-4.3.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<ctx:component-scan base-package="com.abc.xyz"/>
<beans:bean id="resultToDocumentTransformer" class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer"/>
<beans:bean id="resultToStringTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer"/>
<int:channel id="PBWCMAuditInputChannel"/>
<int:channel id="PBWCMInputJMSChannel"/>
<jms:message-driven-channel-adapter id="PBWCMInputJMSAdapter"
destination="FMOB_IN" extract-payload="true"
connection-factory="connectionFactory"
channel="PBWCMAuditInputChannel"
error-channel="errorChannel"/>
<int:service-activator id="PBWCMMessageAuditor"
input-channel="PBWCMAuditInputChannel"
output-channel="PBWCMInputJMSChannel"
ref="mobileMessageAuditor"
method="auditRequest"/>
<si-xml:xpath-router id="wcmRequestRouter" input-channel="PBWCMInputJMSChannel">
<si-xml:mapping value="WCM" channel="WCMChannel"/>
</si-xml:xpath-router>
<si-xml:xpath-router id="WCMRequestRouter" input-channel="WCMChannel">
<si-xml:xpath-expression expression="/faml/request/scrseqnumber"/>
<si-xml:mapping value="01" channel="WCM01ValidateChannel"/>
</si-xml:xpath-router>
<int:channel id="WCM01ValidateChannel"/>
<si-xml:validating-filter id="WCM01Validator"
input-channel="WCM01ValidateChannel"
output-channel="WCM01InChannel"
schema-location="classpath:xsd/request/WCM_01_Request.xsd"
discard-channel="invalidMessageChannel"/>
<int:channel id="WCM01InChannel"/>
<int:channel id="WCM01OutChannel"/>
<si-xml:unmarshalling-transformer id="WCM01Unmarshaller" unmarshaller="WCM01ReqUnmarshaller"
input-channel="WCM01InChannel"
output-channel="WCM01OutChannel"/>
<int:channel id="WCM01ResponseChannel" />
<int:service-activator id="WCM01ServiceActivator"
input-channel="WCM01OutChannel"
output-channel="WCM01ResponseChannel"
ref="WCMRequestProcessor"
method="processWCM01Request"/>
<jms:outbound-channel-adapter id="WCM01ResponseOutAdapter" destination="responseQueue" channel="WCM01ResponseChannel"/>
<beans:bean id="WCM01ReqUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<beans:property name="contextPaths">
<beans:list>
<beans:value>com.abc.xyz.jms.jaxb.WCM_01_request</beans:value>
</beans:list>
</beans:property>
</beans:bean>
</beans:beans>
The JARs available in the lib folder are
org.springframework.integration-1.0.3.RELEASE.jar
org.springframework.integration.jms-1.0.3.RELEASE-1.0.3.RELEASE.jar
org.springframework.integration.stream-1.0.3.RELEASE-1.0.3.RELEASE.jar
spring-beans-4.3.20.RELEASE.jar
spring-context-4.3.18.RELEASE.jar
spring-integration-jms-4.3.17.RELEASE.jar
spring-integration-stream-4.3.17.RELEASE.jar
spring-integration-xml-4.3.17.RELEASE.jar
If I remove this XML from my web.xml (contextConfigLocation), my EAR gets deployed successfully.
Help me figure out the issue in the XML.
All the Spring Integration dependencies must be in the same version. In your case 4.3.17.RELEASE. Same applies for Spring Framework dependencies.
Note: both those versions are EOL already . You need to think to upgrade to the latest one : https://spring.io/projects/spring-integration#learn.
Also, please, study what is dependency management and how you can avoid extra config relying on the transitive dependencies by the library you use.
Another useful tool these days is Spring Boot with its version management: https://spring.io/projects/spring-boot
I am developing an utility in Spring batch will read data from Mysql/Oracle and write it to the Redis database.
Currently we still using Spring Batch XML based configurations (we still like the XML based - gives little control to us :))
When I configured the following I see most of the methods are deprecated.
<bean id="redisDataSource" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name=""></property>
</bean>
using following versions of dependencies:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-batch-vesion>4.0.1.RELEASE</spring-batch-vesion>
<mysql.version>8.0.11</mysql.version>
<logback.version>1.2.3</logback.version>
<jcl.slf4j.version>1.7.25</jcl.slf4j.version>
<quartz.version>2.2.1</quartz.version>
<spring.version>5.0.0.RELEASE</spring.version>
<lombok.version>1.18.0</lombok.version>
<jedis.version>2.9.0</jedis.version>
</properties>
Could anyone please suggest XML based configurations which I should used to configured the dataSource ?
I've taken a reference from the link: https://docs.spring.io/spring-data/redis/docs/2.0.8.RELEASE/reference/html/, but its not clear to me.
STS snippet:
After lot of research and googling found the below useful links :
Weird redis key with spring data Jedis
Spring Data RedisTemplate: Serializing the Value and HashValue
https://github.com/hantsy/spring-sandbox/blob/master/spring-cache/src/main/java/com/hantsylabs/example/spring/config/applicationContext-jpa-redis.xml
Get Set value from Redis using RedisTemplate
Here is the code snippet:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
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.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="200" />
<property name="maxIdle" value="50" />
<property name="maxWaitMillis" value="3000" />
<property name="testOnBorrow" value="true" />
</bean>
<bean id="jedisFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis_ip}" />
<property name="port" value="${redis_port}" />
<property name="poolConfig" ref="jedisPoolConfig" />
<property name="usePool" value="true" />
</bean>
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisFactory" p:valueSerializer-ref="stringRedisSerializer"
p:keySerializer-ref="stringRedisSerializer" />
</beans>
Or Simply used https://docs.spring.io/spring-integration/reference/html/redis.html
I want to build a login with spring social, and I have implemented a *xml whit the next configuration, but the url http://www.springframework.org/schema/social/facebook is wrong?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:facebook="http://www.springframework.org/schema/social/facebook"
xmlns:twitter="http://www.springframework.org/schema/social/twitter"
xmlns:social="http://www.springframework.org/schema/social"
xmlns:linkedin="http://www.springframework.org/schema/social/linkedin"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/social/facebook http://www.springframework.org/schema/social/spring-social-facebook.xsd
http://www.springframework.org/schema/social/linkedin http://www.springframework.org/schema/social/spring-social-linkedin.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/social/twitter http://www.springframework.org/schema/social/spring-social-twitter.xsd
http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:/itrippingWeb/src/main/resources/application.properties" />
<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}" app-namespace="socialshowcase" />
<social:jdbc-connection-repository/>
<bean id="userIdSource" class="org.springframework.social.security.AuthenticationNameUserIdSource" />
<bean id="connectController" class="org.springframework.social.connect.web.ConnectController" autowire="constructor">
<property name="connectInterceptors">
<list>
<bean class="org.springframework.social.showcase.facebook.PostToWallAfterConnectInterceptor" />
<bean class="org.springframework.social.showcase.twitter.TweetAfterConnectInterceptor" />
</list>
</property>
</bean>
<bean id="psc" class="org.springframework.social.connect.web.ProviderSignInController" autowire="constructor" />
<bean id="signInAdapter" class="org.springframework.social.showcase.signin.SimpleSignInAdapter" autowire="constructor" />
<bean id="disconnectController" class="org.springframework.social.facebook.web.DisconnectController"
c:_0-ref="usersConnectionRepository" c:_1="${facebook.clientSecret}" />
</beans>
And this xml retrieve me the next exception:
Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element
'facebook:config'.
- schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/social/spring-
social-facebook.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element
of the document is not <xsd:schema>.
Anybody knows the problem?
thank you!!!!
I think this has to do with your pom missing some of the dependencies.
Is spring-social-security in your dependency?
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.1.0.RELEASE</version>
Here is a similar application with the same config as your spring xml above. Here is the pom it uses https://github.com/spring-projects/spring-social-samples/blob/master/attic/spring-social-showcase-xml/pom.xml
Here is a reference to a similar error resolved by fixing the pom dependency https://github.com/spring-projects/spring-social-facebook/issues/79
Actually the url "http://www.springframework.org/schema/social/facebook" links to nowhere.
I found another schema files location: http://docs.spring.io/autorepo/schema/
I used "http://docs.spring.io/autorepo/schema/spring-social/current/social/spring-social.xsd" and it works for me.
I am using Spring 3.1 to create a bean in an web application like below wherein the server contains -DCONFIG_MODE=dev. However, it seems spring is only resolving the filename to configuration.dev without appending the remaining .xml. Could you please point what could be wrong in this.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd">
<bean id="xmlConfig" class="org.quwic.itms.mq.XmlConfiguration" init-method="init">
<constructor-arg type="java.net.URL" value="classpath:configuration.#{systemProperties.CONFIG_MODE}.xml"/>
<constructor-arg type="org.apache.commons.configuration.reloading.ReloadingStrategy" ref="reloadingStrategy"/>
</bean>
<!-- The managed reloading strategy for the configuration bean -->
<bean id="reloadingStrategy" class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy">
<property name="refreshDelay" value="300000"/>
</bean>
</beans>
Thanks,
Fixed it. I wrongly specified the system property as "-DCONFIG_MODE=local -Dprogram.name=JBossTools: JBoss 5.0 Runtime" rather than -DCONFIG_MODE=local "-Dprogram.name=JBossTools: JBoss 5.0 Runtime"
I have a standalone spring application with an embedded Apache FTP server. The config looks like this -
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:afs="http://mina.apache.org/ftpserver/spring/v1"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd">
<context:property-placeholder location="classpath:config.properties" system-properties-mode="OVERRIDE"/>
<afs:server id="server" anon-enabled="false">
<afs:listeners>
<afs:nio-listener name="default" port="2222"
idle-timeout="60" />
</afs:listeners>
<!-- other AFS config -->
</afs:server>
</beans>
I would like to load the port property of nio-listener from a properties files, but
<afs:nio-listener name="default" port="${ftp.port}"
idle-timeout="60" />
doesn't work, since port is defined in the xsd as xs:int. I'd like to know if there is any workaround (using SpEL?) that will allow me to use the AFS namespace and load the port property from a file or from system properties.
You could try with PropertyOverrideConfigurer.
The problem is that you need to know the bean name that the <afs:server> tag define (may be 'server') and the property type that <afs:listeners> define (may be a managed list of bean definitions).
Look at STS bean explorer to find correct answers and try whith something like
<context:property-override location="classpath:config.properties" />
server.listeners[0].port=2222
Other option is disable schema validation setting validating to false before refresh in the xml application context.
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"applicationContext.xml"}, false);
context.setValidating(false);
context.refresh();
After exploring a few options, I've decided that the easiest way is to step outside the afs namespace for the just the listener configuration. Final config looks like this -
<bean id="listenerFactory" class="org.apache.ftpserver.listener.ListenerFactory">
<property name="port" value="${ftp.port}" />
<property name="dataConnectionConfiguration">
<bean factory-bean="dataConnectionConfigurationFactory"
factory-method="createDataConnectionConfiguration" />
</property>
</bean>
<bean id="dataConnectionConfigurationFactory" class="org.apache.ftpserver.DataConnectionConfigurationFactory" />
<bean id="nioListener" factory-bean="listenerFactory" factory-method="createListener" />
<afs:server id="server" anon-enabled="false">
<afs:listeners>
<afs:listener name="default">
<ref bean="nioListener"/>
</afs:listener>
</afs:listeners>
<!-- other AFS config -->
</<afs:server>