我有一个基于Spring Data和MongoDB的简单项目。当我使用以下Spring上下文将此项目部署到云中时:
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://schema.cloudfoundry.org/springhttp://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsdhttp://www.springframework.org/schema/data/jpahttp://www.springframework.org/schema/data/jpa/spring-jpa.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-2.0.xsdhttp://www.springframework.org/schema/data/mongohttp://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<context:property-placeholder location="classpath:services.properties" />
<context:annotation-config />
<bean id="gadgetizerApplication" class="it.ids.gadgetizer.GadgetizerApplication">
</bean>
<bean id="gadgetizerService" class="it.ids.gadgetizer.service.impl.GadgetServiceImpl">
<property name="mongoTemplate" ref="mongoTemplate" />
<property name="mailSender" ref="mailSender"/>
<property name="velocityEngine" ref="velocityEngine"/>
</bean>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mail.xxx.xxx" />
<property name="username" value="xxx"/>
<property name="password" value="xxx"/>
<property name="port" value="2525"/>
</bean>
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<value>
resource.loader=class
class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</value>
</property>
<beans profile="development">
<mongo:db-factory id="mongoDbFactory" dbname="${mongo.dbname}" host="${mongo.host}" port="${mongo.port}" />
</beans>
<beans profile="cloud">
<cloud:mongo-db-factory id="mongoDbFactory" service-name="${mongo.cloud.service_name}" />
</beans>
它失败了:
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplate]: Constructor threw exception; nested exception is java.lan
.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:110)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
... 68 more
Caused by: java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.util.Assert.notNull(Assert.java:123)
at org.springframework.data.mongodb.core.MongoTemplate.(MongoTemplate.java:196)
at org.springframework.data.mongodb.core.MongoTemplate.(MongoTemplate.java:185)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 70 more
Stopping Tomcat because the context stopped.
它一个月前还在工作。API发生了什么变化?
感谢
您的问题似乎是运行时jar。请尝试使用最新的cloudfoundry运行时。