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

时间:2016-08-27 10:15:39

标签: mysql spring-mvc ibm-cloud cloudfoundry

我已使用Cloud Foundry成功将我的Spring MVC应用程序推送到云端。但是,当我尝试访问URL时出现以下异常:

  

错误500:javax.servlet.ServletException:SRVE0207E:未捕获   servlet创建的初始化异常

以下是访问网址时出现的错误:

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$1.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配置中包含了所有这些内容,是否有任何问题?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

相关问题