【问题标题】:Cloudfoundry Spring MongoDB sample application fails to deployCloudfoundry Spring MongoDB 示例应用程序部署失败
【发布时间】:2012-08-27 21:44:33
【问题描述】:

当我尝试使用 MongoDB (hello-spring-mongodb) 部署示例 Java Spring 应用程序时,我收到下面粘贴的错误,这表明 MongoDB 服务无法绑定。我在自己的所有应用程序中也遇到了这个错误,从命令行和 STS 3.0.0 部署。关键错误是:

创建名为 'mongoDbFactory' 的 bean 时出错:调用 init 方法失败;嵌套异常是 org.cloudfoundry.runtime.env.CloudServiceException:预期 1 类 org.cloudfoundry.runtime.env.MongoServiceInfo 类型的服务,但发现0

完整的跟踪:

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)

【问题讨论】:

    标签: spring mongodb cloud-foundry


    【解决方案1】:

    替换:

    <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>
    

    与:

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

    ...并且 cloudfoundry 自动重新配置将正确完成它的工作。如果仍有问题,请在 Spring Explorer View > Properties 中右键单击您的项目,然后启用“Beans Validator”。

    【讨论】:

      【解决方案2】:

      您是否更改了预期的 mongo db 的名称? hello-spring-mondgodb 应用程序是 configured 以查找名为“hello”的数据库(SimpleMongoDbFactory 的第二个构造函数 arg)。也许尝试更新此属性以反映您的 mongo db 的名称并重新推送。

      希望对你有帮助

      克里斯

      【讨论】:

        【解决方案3】:

        hello-spring-mongodb 无需更改配置即可运行。它在我的 CF 安装上成功部署。首先,我创建了一个 mongoDB 服务:

        vmc create-service mongoDB
        

        然后我从目标目录运行:vmc push hello-sping-mongodb

        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
        

        可以尝试先创建mongoDB服务再推送应用吗?

        【讨论】:

        • 这令人费解。我首先尝试创建 MongoDB 服务,尝试为它命名各种东西,尝试了我能想到的一切。我在 OSX 上。有效的一件事是删除 Spring 配置文件的使用并让 Cloud Foundry 自动重新配置我用于本地测试的 MongoDbFactory bean。
        • 我没有改行——只是直接从上面链接的 github repo 中克隆出来的。
        【解决方案4】:

        您的 root-context.xml 中似乎没有定义云配置文件配置。再次检查您是否具有以下配置:

        <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>
        

        【讨论】:

        • 非常感谢您参与其中,但同样,我是直接从 repo 克隆的——这正是我的 root-context.xml 的样子。似乎我可能不是唯一遇到此错误的人:stackoverflow.com/questions/12132688/…
        • 重现此错误的唯一方法是将云配置文件放入 cmets。
        【解决方案5】:

        确保服务名称匹配,并更新 cloudfoundry-runtime 版本。请参阅我对另一个问题的回答,但有相同的例外 here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-06-09
          • 2016-06-17
          • 1970-01-01
          • 2018-04-12
          • 1970-01-01
          • 2017-02-05
          • 1970-01-01
          相关资源
          最近更新 更多