如何在 Bluemix 上 运行 Spring MVC 项目?

How to run a Spring MVC project on Bluemix?

我已经使用 Cloud Foundry 成功地将我的 Spring MVC 应用程序推送到云端。但是,当我尝试访问 URL:

时出现以下异常

Error 500: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet

这是我访问URL时得到的错误:

App/0[ERROR ] Context initialization failed2016-08-27T16:12:30.073+0530
App/0Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.covenant.app.dao.UserRepository com.covenant.app.services.UserService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined2016-08-27T16:12:30.073+0530
App/0 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)2016-08-27T16:12:30.075+0530
App/0 at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2390)2016-08-27T16:12:30.075+0530
App/0Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:667)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)2016-08-27T16:12:30.074+0530
App/0[ERROR ] SRVE0271E: Uncaught init() exception created by servlet [dispatcher] in application [myapp]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.covenant.app.dao.UserRepository com.covenant.app.services.UserService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined2016-08-27T16:12:30.074+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:528)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:302)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)2016-08-27T16:12:30.075+0530
App/0 ... 28 more2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:572)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:354)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:694)2016-08-27T16:12:30.075+0530
App/0 at [internal classes]

任何帮助将不胜感激,因为我被困在这个时间点。我的所有 spring MVC 配置都在 Java 配置中。部署到 Bluemix 时,如果我的 Java 配置中包含所有这些,会有什么问题吗?

错误是我使用 DriverManager 调用 MySQL 的本地数据源以获取数据源。但是,当我将它更改为 Basic DataSource for Bluemix 时,它开始工作了。

我已阅读文章并能够使用 bluemix 部署和测试 Spring MVC。 将 MySQL 修改为 dashDB(相当于 IBM DB2)。 URL 是 http://www.codejava.net/frameworks/spring/spring-mvc-with-jdbctemplate-example。还使用 DB2 和 IBM Liberty Server 在本地进行了测试,并且可以正常工作。