Can't load property file for property-placeholder - spring

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.

Related

Apache camel Spring Profiles

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

Spring configuration doesn't recognise mvc:annotation-driven tag

I am not able to use "mvc" namespace in my spring configuration file, for a simple spring mvc based web-application which I am developing.
Here is the xml snippet:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.example.controller" annotation-config="true"/>
<context:annotation-config/>
<mvc:annotation-driven/> <-- For this eclipse shows red "*" meaning error
<bean id="viewResolver1" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"> <value>/WEB-INF/</value> </property>
<property name="suffix"> <value>.jsp</value> </property>
</bean>
</beans>
It is not recognising the mvc:annotation-driven tag, but able to recognise other tags from different namespace, for example context:annotation-config.
All this was working fine (I am using Eclipse IDE), only a day before it is giving me this error. I have not changed anything in the environment.
Can anyone please help in how to solve this issue?

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>

MongoDB database creation with spring data

I am creating a sample web application with spring 3.0 and mongoDB. Following is my root-context.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<!-- Root Context: defines shared resources visible to all other web components -->
<import resource="classpath:mongo-config.xml"/>
</beans>
and my mongo-config.xml file is
<?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:c="http://www.springframework.org/schema/c"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-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/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<!-- Default bean name is 'mongo'. write concern set to SAFE to ensure unique indexes -->
<mongo:mongo host="localhost" port="27017" write-concern="SAFE"/>
<mongo:repositories base-package="com.dashboard.repositories" />
<bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
<constructor-arg name="mongo" ref="mongo"/>
<constructor-arg name="databaseName" value="DASHBOARD"/>
<constructor-arg name="credentials" ref="userCredentials"/>
</bean>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
<property name="writeResultChecking">
<util:constant static-field="org.springframework.data.mongodb.core.WriteResultChecking.EXCEPTION" ></util:constant>
</property>
</bean>
<bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials">
<constructor-arg name="username" value="test"/>
<constructor-arg name="password" value="abc123"/>
</bean>
</beans>
when i start the tomcat server, there is no database "Dashboard" created. What is wrong with this code, Kindly help me. Thanks in advance.
For making it visible to other viewers i will put my comment into the answer. In Mongo schemas are dynamic and heterogenous so mongo cannot create a fixed schema as RDMS before inserting any data. Here is a more detailed explanation.

Resources