Ben
Ben

Reputation: 31

Cloudfoundry Spring MongoDB sample application fails to deploy

When I try to deploy the sample Java Spring application with MongoDB (hello-spring-mongodb) I get the error pasted below, which suggests the MongoDB service is failing to bind. I have been getting this error in all my own applications too, deploying both from the command line and from STS 3.0.0. The key error is:

Error creating bean with name 'mongoDbFactory': Invocation of init method failed; nested exception is org.cloudfoundry.runtime.env.CloudServiceException: Expected 1 service of class org.cloudfoundry.runtime.env.MongoServiceInfo type, but found0

Full trace:

Bind existing services to 'hello-weeels'? [yN]: 
Create services to bind to 'hello-weeels'? [yN]: y
1: mongodb
2: mysql
3: postgresql
4: rabbitmq
5: redis
What kind of service?: 1
Specify the name of the service [mongodb-9c56b]: 
Create another? [yN]: n
Would you like to save this configuration? [yN]: y
Manifest written to manifest.yml.
Creating Application: OK
Creating Service [mongodb-9c56b]: OK
Binding Service [mongodb-9c56b]: OK
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (3K): OK   
Push Status: OK
Staging Application 'hello-weeels': OK                                          
Starting Application 'hello-weeels': ..
Error: Application [hello-weeels] failed to start, logs information below.

====> /logs/stderr.log <====

Aug 27, 2012 9:17:24 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-54519
Aug 27, 2012 9:17:24 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 392 ms
Aug 27, 2012 9:17:24 PM org.apache.catalina.realm.JAASRealm setContainer
INFO: Set JAAS app name Catalina
Aug 27, 2012 9:17:24 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Aug 27, 2012 9:17:24 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
Aug 27, 2012 9:17:24 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Aug 27, 2012 9:17:24 PM org.cloudfoundry.reconfiguration.CloudAutoStagingBeanFactoryPostProcessor usingCloudService
INFO: Found an instance of org.cloudfoundry.runtime.service.AbstractCloudServiceFactory.  Autostaging will be skipped.
Aug 27, 2012 9:17:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Aug 27, 2012 9:17:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [] startup failed due to previous errors

====> /logs/stdout.log <====

INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Aug 27 21:17:24 UTC 2012]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [root-context.xml]
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/cloud/cloudfoundry-auto-reconfiguration-context.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c292cb2: defining beans [mongoTemplate,mongoDbFactory,__appCloudJpaPostgreSQLReplacementProperties,__appCloudJpaMySQLReplacementProperties,__appCloudHibernatePostgreSQLReplacementProperties,__appCloudHibernateMySQLReplacementProperties,org.cloudfoundry.reconfiguration.CloudAutoStagingBeanFactoryPostProcessor#0]; root of factory hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c292cb2: defining beans [mongoTemplate,mongoDbFactory,__appCloudJpaPostgreSQLReplacementProperties,__appCloudJpaMySQLReplacementProperties,__appCloudHibernatePostgreSQLReplacementProperties,__appCloudHibernateMySQLReplacementProperties,org.cloudfoundry.reconfiguration.CloudAutoStagingBeanFactoryPostProcessor#0]; root of factory hierarchy
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [root-context.xml]: Cannot resolve reference to bean 'mongoDbFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDbFactory': Invocation of init method failed; nested exception is org.cloudfoundry.runtime.env.CloudServiceException: Expected 1 service of class org.cloudfoundry.runtime.env.MongoServiceInfo type, but found0
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:630)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)

Upvotes: 3

Views: 2444

Answers (5)

Luke
Luke

Reputation: 764

Make sure the service name matches, and update the cloudfoundry-runtime version. See my answer to another question with the same exception here.

Upvotes: 0

eightyoctane
eightyoctane

Reputation: 639

Replace:

<beans profile="default">
    <mongo:db-factory id="mongoDbFactory" dbname="pwdtest" host="127.0.0.1" port="27017"    username="mongo_user" password="passwd"/>
</beans>

<beans profile="cloud">
    <cloud:mongo-db-factory id="mongoDbFactory"/>
</beans>

With:

<mongo:db-factory
    id="mongoDbFactory"
    dbname="${mongo.name}"
    host="${mongo.host}"
    port="27017"
    username="${mongo.username}"
    password="${mongo.password}" />

...and cloudfoundry auto reconfig will do it's job properly. If you still have a problem, Right-click on your project in the Spring Explorer View > Properties, and enable the "Beans Validator".

Upvotes: 5

Nikos Berdos
Nikos Berdos

Reputation: 161

It seems that the cloud profile configuration isn't defined in your root-context.xml. Check again that you have the following configuration:

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg ref="mongoDbFactory"/>     
</bean>


<beans profile="default">
    <mongo:db-factory id="mongoDbFactory" dbname="pwdtest" host="127.0.0.1" port="27017" username="mongo_user" password="passwd"/>
</beans>

<beans profile="cloud">
    <cloud:mongo-db-factory id="mongoDbFactory"/>
</beans>

Upvotes: 0

Nikos Berdos
Nikos Berdos

Reputation: 161

The hello-spring-mongodb runs without configuration changes. It deploys successfully on my CF installation. First, I create a mongoDB service with:

vmc create-service mongoDB

and then I run: vmc push hello-sping-mongodb from the target directory

C:\eclipseWork\Indigo\hello-spring-mongodb\target>vmc push hello-spring-mongodb
Would you like to deploy from the current directory? [Yn]:
Detected a Java SpringSource Spring Application, is this correct? [Yn]:
Application Deployed URL [hello-spring-mongodb.vcap.me]:
Memory reservation (128M, 256M, 512M, 1G, 2G) [512M]:
How many instances? [1]:
Bind existing services to 'hello-spring-mongodb'? [yN]: y
1: mongodb-86f0e
Which one?: 1
Create services to bind to 'hello-spring-mongodb'? [yN]:
Would you like to save this configuration? [yN]:
Creating Application: OK
Binding Service [mongodb-86f0e]: OK
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (2K): OK
Push Status: OK
Staging Application 'hello-spring-mongodb': OK
Starting Application 'hello-spring-mongodb': OK

Can you try to create the mongoDB service first and then push the application?

Upvotes: 0

Chris Hedley
Chris Hedley

Reputation: 3

Did you change the name of the expected mongo db? The hello-spring-mondgodb app is configured to to look for a db named 'hello' (The second constructor arg of SimpleMongoDbFactory). Maybe try updating this property to reflect the name of your mongo db and re-push.

Hope this helps

Chris

Upvotes: 0

Related Questions