gpt4 book ai didi

spring - Cloudfoundry Spring MongoDB 示例应用程序部署失败

转载 作者:可可西里 更新时间:2023-11-01 09:28:10 26 4
gpt4 key购买 nike

当我尝试使用 MongoDB ( hello-spring-mongodb ) 部署示例 Java Spring 应用程序时,我收到下面粘贴的错误,这表明 MongoDB 服务无法绑定(bind)。我也在我自己的所有应用程序中遇到此错误,从命令行和 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)

最佳答案

替换:

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

关于spring - Cloudfoundry Spring MongoDB 示例应用程序部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12150018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com