我下载了STS 3.0.0并且一直试图使用Roo将简单的弹簧应用程序放到CloudFoundry上。
第1步:这是我的roo脚本
// Spring Roo 1.2.2.RELEASE [rev 7d75659] log opened at 2012-08-26 22:36:52
project --topLevelPackage com.nroots.tracker
mongo setup --cloudFoundry true
entity mongo --class ~.domain.Trackable --testAutomatically
field string --fieldName name --notNull --sizeMin 3
field date --fieldName datetime --type java.util.Date --dateTimeFormatPattern yyyyMMddHHmmssSSS
repository mongo --interface ~.repository.TrackableRepository --entity ~.domain.Trackable
service --interface ~.service.TrackableService --entity ~.domain.Trackable
web mvc setup
web mvc all --package ~.web
logging setup --level DEBUG --package ROOT
logging setup --level DEBUG --package PROJECT
perform eclipse
第2步:将项目导入STS 我得到一个对话框询问我是否要转换旧的STS项目,我选择是。项目将被导入并成功构建。
第3步:在roo shell仍然运行的情况下,我修改了Trackable域类并添加了一个double []数组来保存gps坐标。然后在Package Explorer视图中,我做了一个Refactor>推入 该项目再次成功建立。
第4步:部署到CloudFoundry 使用STS CloudFoundry扩展,我创建了一个新的VMware CloudFoundry服务器并添加我的应用程序并将其绑定到MongoDB服务......
但是,我在部署期间在控制台视图中收到这些例外:
2012-08-26 18:05:41,367 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'trackableServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.nroots.tracker.repository.TrackableRepository com.nroots.tracker.service.TrackableServiceImpl.trackableRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'trackableRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'template'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in file [/var/vcap/data/dea/apps/tracker-0-36d30b53f85ac47671b723302407a7ec/tomcat/webapps/ROOT/WEB-INF/classes/META-INF/spring/applicationContext-mongo.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 found 0
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.nroots.tracker.repository.TrackableRepository com.nroots.tracker.service.TrackableServiceImpl.trackableRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'trackableRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'template'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in file [/var/vcap/data/dea/apps/tracker-0-36d30b53f85ac47671b723302407a7ec/tomcat/webapps/ROOT/WEB-INF/classes/META-INF/spring/applicationContext-mongo.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 found 0
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 37 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'trackableRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'template'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in file [/var/vcap/data/dea/apps/tracker-0-36d30b53f85ac47671b723302407a7ec/tomcat/webapps/ROOT/WEB-INF/classes/META-INF/spring/applicationContext-mongo.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 found 0
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.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in file [/var/vcap/data/dea/apps/tracker-0-36d30b53f85ac47671b723302407a7ec/tomcat/webapps/ROOT/WEB-INF/classes/META-INF/spring/applicationContext-mongo.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 found 0
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)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 52 more
Caused by: 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 found 0
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 64 more
Caused by: org.cloudfoundry.runtime.env.CloudServiceException: Expected 1 service of class org.cloudfoundry.runtime.env.MongoServiceInfo type, but found 0
at org.cloudfoundry.runtime.service.AbstractServiceCreator.createSingletonService(AbstractServiceCreator.java:53)
at org.cloudfoundry.runtime.service.AbstractCloudServiceFactory.createInstance(AbstractCloudServiceFactory.java:46)
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)
... 71 more
Stopping Tomcat because the context stopped.
答案 0 :(得分:2)
将applicationContext-mongo.xml更改为如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cloud="http://schema.cloudfoundry.org/spring" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd">
<mongo:repositories base-package="com.nroots.tracker"/>
<context:annotation-config/>
<mongo:db-factory
id="mongoDbFactory"
dbname="${mongo.name}"
host="${mongo.host}"
port="${mongo.port}"
username="${mongo.username}"
password="${mongo.password}" />
<bean class="org.springframework.data.mongodb.core.MongoTemplate" id="mongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
</bean>
</beans>
删除该行:
<cloud:mongo-db-factory id="mongoDbFactory"/>
答案 1 :(得分:1)
我首先添加了一个service-name属性来解决这个异常:
<cloud:mongo-db-factory id="mongoDbFactory" service-name="my-service-name"/>
其中“my-service-name”是我在STS中为MongoDB服务设置的名称。
然后我遇到一个关于MongoTemplate构造函数参数为null的异常,我通过将cloudfoundry-runtime版本从0.8.0更新到0.8.2来解决这个问题。
答案 2 :(得分:0)
Spring似乎无法实例化绑定到您的CF mongo服务的mongoDbFactory。我假设您的配置类似于以下内容:
<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 name" host="127.0.0.1" port="27017" username="username" password="changeme"/>
</beans>
<beans profile="cloud">
<cloud:mongo-db-factory id="mongoDbFactory"/>
</beans>
您的应用程序是否在本地运行?