问题描述
我下载了STS 3.0.0,并一直试图使用Roo将一个简单的spring应用程序安装到CloudFoundry上。
I downloaded STS 3.0.0 and have been trying to get a simple spring app onto CloudFoundry using Roo.
步骤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:导入pr注入STS
我得到一个对话框,询问我是否要转换旧版STS项目,然后选择是。项目已导入并成功构建。
STEP 2: Import the project into STSI get a dialog asking me if I want to convert the legacy STS project and I select yes. The project gets imported and builds successfully.
步骤3:在roo shell仍在运行的情况下,我修改了Trackable域类并添加了一个double []数组,用于保存GPS坐标。然后在Package Explorer视图中,执行Refactor> Push In
项目再次成功构建。
STEP 3: With the roo shell still running, I modify the Trackable domain class and add a double[] array to hold gps coordinates. And then in the Package Explorer View, I do a Refactor > Push InThe project builds successfully again.
步骤4:部署到CloudFoundry
使用STS CloudFoundry扩展,创建了一个新的VMware CloudFoundry服务器,并添加了我的应用程序并将其绑定到MongoDB服务...
STEP 4: Deploy to CloudFoundryUsing the STS CloudFoundry extension, I created a new VMware CloudFoundry server and add my application and bind it to a MongoDB service...
但是,在部署过程中,我在控制台视图中得到了以下异常:
However, I get these exceptions in the Console View during deployment:
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.
推荐答案
更改applicationContext-mongo.xml如下所示:
Change your applicationContext-mongo.xml to look like this:
<?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"/>
这篇关于带有Spring Roo 1.2.2的STS 3.0.0无法使用MongoDB服务部署到CloudFoundry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!