开发者社区> 问答> 正文

cloudfoundry不能正确创建mongodb服务?报错

在搭建cloudfoundry实例时候,不能成功创建mongo服务,求指导啊

参考了各种文档如,

https://github.com/cloudfoundry/vcap-java/tree/master/cloudfoundry-runtime

也用vmc或sts创建,还是报错:

Caused by: org.cloudfoundry.runtime.env.CloudServiceException: Expected 1 service of class org.cloudfoundry.runtime.env.MongoServiceInfo type, but found0
	at org.cloudfoundry.runtime.service.AbstractCloudServiceFactory.createInstance(AbstractCloudServiceFactory.java:62)
	at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:130)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
	... 61 more
下面是spring配置文件中的配置:
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
		<constructor-arg ref="mongoDbFactory" />
	</bean>

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

	<beans profile="cloud">
		<cloud:mongo-db-factory id="mongoDbFactory" />
	</beans>
其中在controller中直接配置:
@Autowired(required = false)
    MongoTemplate mongoTemplate;

这有什么问题没?貌似文档也仔细看了

o,用的cloudfoundry-runtime 0.8.1

<dependency>
<groupId>org.cloudfoundry</groupId>
<artifactId>cloudfoundry-runtime</artifactId>
<version>0.8.1</version>
</dependency>

展开
收起
爱吃鱼的程序员 2020-06-22 22:24:38 512 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    无奈之下搞定了,需要这样配置:

    <beanid="mongoTemplate"class="org.springframework.data.mongodb.core.MongoTemplate"><constructor-argref="mongoDbFactory"/></bean><mongo:db-factoryid="mongoDbFactory"/>

    同学。。。你是怎么知道的啊??求解,求加好友,我搞了好久看到你的才搞定的
    2020-06-22 22:24:57
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载
MongoDB多数据中心的方案选型之路 立即下载
饿了么高级架构师陈东明:MongoDB是如何逐步提高可靠性的 立即下载

相关镜像