Apache camel Spring Profiles - spring

HI Is there any example for blog post for apache camel using spring profiles for different DB properties.
I'm trying like below
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="Demo" xmlns="http://camel.apache.org/schema/spring">
<Db properties >
<beans:beans profile="dev">
<context:property-placeholder properties-ref="properties" ignore-unresolvable="true"/>
<util:properties id="properties" location="classpath:dev.properties"/>
<context:component-scan base-package="com.demo.environment" />
</beans:beans>
<beans:beans profile="test">
<context:property-placeholder properties-ref="properties" ignore-unresolvable="true"/>
<util:properties id="properties" location="classpath:test.properties"/>
<context:component-scan base-package="com.demo.environment" />
</beans:beans>
</beans:beans>
Its giving Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'bean'. One of '{"http://www.springframework.org/schema/beans":beans}' is expected.
Can any one help here, I'm using camel 2.17.3 version

Related

The matching wildcard is strict, but no declaration can be found for element 'context:include-filter'

Spring Filter components in auto scanning
the below xml gives error, it says no declaration can be found for element 'context:include-filter'.
everything seems fine to me.
using spring 3.0 release
<?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: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">
<context:annotation-config />
<context:component-scan base-package="ComponentFiltering" />
<context:include-filter type="regex"
expression="ComponentFiltering.Data.*Dat.*" />
</beans>

Old versions of spring-integration-sftp in the spring-config file give the XML error but version 3.0.2 gives the error for outbound-channel-adapter

Please see the beginning of the spring-integration-config file below. If I have the reference to spring-integration-sftp (not version 3.02.) in the schema location I am receiving the following error:
Referenced file contains errors (http://www.springframework.org/schema/integration/spring-integration-2.0.xsd).
However, if I switch to the 3.0.2 version of spring-integration-sftp I am getting the following error:
The matching wildcard is strict, but no declaration can be found for element 'int-sftp:outbound-channel-adapter'.
The spring-integration-config.xml code related to spring-integration-sftp is as follows:
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="${seaWorldOrlando.sftp.host}" />
<property name="port" value="${seaWorldOrlando.sftp.port}" />
<property name="user" value="${seaWorldOrlando.sftp.user}" />
<property name="password" value="${seaWorldOrlando.sftp.password}" />
</bean>
<int-sftp:outbound-channel-adapter
id="sftpOutboundAdapter" channel="toFtp" charset="UTF-8"
remote-directory="/home/request" session-factory="sftpSessionFactory" />
The beginning of the spring-integration-config file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-3.0.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd">
Our recommendation do not use versions for XSD at all. The framework read the latest one from classpath. it allow you to avoid changes after upgrade.
From other side, if you mention 3.0.2 be sure you use correct jars of Spring Integration.
And all of them should be the same version.
If you have some doubts with allowed attributes, take a look into correct XSD, if they are present. You can find them in the appropriate jar, e.g. org/springframework/integration/sftp/config/spring-integration-sftp-3.0.xsd.

spring context error with processing xml

I have problem with processing root-context with really simple content. I just want to configure camel-client and camel proxy beans but I get:
Error occured processing XML 'Provider
com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1
counts of IllegalAnnotationExceptions Class has two properties of
the same name "outputs" this problem is related to the following
location: at public java.util.List
org.apache.camel.model.ResequenceDefinition.getOutputs() at
org.apache.camel.model.ResequenceDefinition this problem is related to
the following location: at private java.util.List
org.apache.camel.model.ResequenceDefinition.outputs at
org.apache.camel.model.ResequenceDefinition '. See Error Log for more
details
This is my root-context.xml:
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
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.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<camel:camelContext id="camel-client">
</camel:camelContext>
<!-- Camel proxy for a given service, in this case the JMS queue -->
<camel:proxy
id="serviceProxy"
camelContextId="camel-client"
serviceInterface="pl.test.Service"
serviceUrl="jms:queue:test?transferException=true"/>
<bean id="jboss" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<jee:jndi-lookup id="connectionFactory" jndi-name="QueueConnectionFactory">
</jee:jndi-lookup>
</beans>
I have camel dependancies in my pom.xml. Anyone could give me a hint where I am doing the mistake?
According to the Camel proxy documentation <camel:proxy> must be within <camel:camelContext>:
<camel:camelContext id="camel-client">
<camel:proxy
id="serviceProxy"
camelContextId="camel-client"
serviceInterface="pl.test.Service"
serviceUrl="jms:queue:test?transferException=true"/>
</camel:camelContext>

Spring 'application-context' XSD schema read issue

I'm using JAXWS in my spring project to communicate with server and there is an error of XSD reading in my application context xml. Here is the application context -
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ws="http://jax-ws.java.net/spring/core"
xmlns:wss="http://jax-ws.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
//**error at this below line -** **cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'wss:binding'.**
<wss:binding url="/hello">
<wss:service>
<ws:service bean="#helloWs"/>
</wss:service>
</wss:binding>
<!-- Web service methods -->
<bean id="helloWs" class="com.mkyong.ws.HelloWorldWS">
<property name="helloWorldBo" ref="HelloWorldBo" />
</bean>
<bean id="HelloWorldBo" class="com.mkyong.bo.impl.HelloWorldBoImpl" />
Can any one please let me know what could be the reason for this error and any solution.
Thanks for any help.!
Why don't you try the following xml:
<?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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://jax-ws.dev.java.net/spring/core http://jax-ws.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet http://jax-ws.java.net/spring/servlet.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<wss:binding url="/hello">
<wss:service>
<ws:service bean="#helloWs"/>
</wss:service>
</wss:binding>
<!-- Web service methods -->
<bean id="helloWs" class="com.mkyong.ws.HelloWorldWS">
<property name="helloWorldBo" ref="HelloWorldBo" />
</bean>
<bean id="HelloWorldBo" class="com.mkyong.bo.impl.HelloWorldBoImpl" /> </beans>
are you using spring in your project?, I had the same problem, but when I included spring-jaxws in my maven dependencies the problem solved, in fact, yo can see in that jar that the META-INF/spring.schemas file is redefining the XSDs locations:
http\://jax-ws.java.net/spring/core.xsd=spring-jax-ws-core.xsd
http\://jax-ws.java.net/spring/servlet.xsd=spring-jax-ws-servlet.xsd
http\://jax-ws.java.net/spring/local-transport.xsd=spring-jax-ws-local-transport.xsd
I wish it helps!

Can't load property file for property-placeholder

my property file is under the following path:
src\main\resources\META-INF\app-config.properties
and my spring configuration files are under the path:
WebContent\WEB-INF
and when trying to load the property file as follows:
<context:property-placeholder
location="classpath:META-INF/app-config.properties" />
i am getting the exception:
java.io.FileNotFoundException: class path resource [META-INF/app-config.properties] cannot be opened because it does not exist
applicationContext.xml
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:oxm="http://www.springframework.org/schema/oxm" 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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<import resource="application-Security-Context.xml" />
<import resource="application-DataAccess-Context.xml" />
<import resource="application-Service-Context.xml" />
<context:component-scan base-package="com.myapp" />
<!-- PERSISTENCE -->
<context:property-placeholder
location="classpath:META-INF/app-config.properties" />
<jee:jndi-lookup id="appDS" jndi-name="MyApp" expected-type="javax.sql.DataSource"/>
<bean id="persistenceUnitManager"
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="appDS" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
<property name="persistenceUnitName" value="MyApp" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
applicationContext is loaded in web.xml as follows:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
i am using ant to build my project, am i missing ant configuration or eclipse configuration for this issue ?
ant config:
<zipfileset dir="${basedir}/src/main/resources/META-INF" includes="app-config.properties" fullpath="WEB-INF/classes/META-INF/app-config.properties"/>
also i added the META-INF folder to the deployment assembly in eclipse.
please advise how to load this property file correctly.
Can u try <context:property-placeholder
location="classpath*:META-INF/app-config.properties" />
If this also fails then may be your src\main\resources is not under the classpath.
I think the problem is in your path defined for properties file.
Can you try the following one.
<context:property-placeholder location="classpath:/META-INF/app-config.properties" />
Hope this helps you.
Taking a bit of a guess here, as you say you are using eclipse, but not exactly when the exception occurs - from eclipse or the command line. If from within Eclipse, then you will need to align the Eclipse project settings with those Ant is using. Go under Project-Properties, but rather than the deployment assembly, go to the Java Build path and verify that all of your source inputs (both code and resources) are there. More importantly, verify that the output directories are set to the same ones Ant is using. Long shot, but worth a try!
Is the properties file actually in your compiled artifact? Can you show us a directory listing of your unzipped artifact so we can see if the file is present? Or are you running it right from Eclipse and the error comes there? If so, you need to adjust your Project Properties to include the directory and/or file.

Resources