1

我有使用 Spring JPA 和 Hibernate 开发应用程序的经验。我设置了我的数据源,如 http://blog.springsource.org/2011/11/04/using-cloud-foundry-services-with-spring-part-2-auto-reconfiguration/中所述,使用 xml 标签“ <cloud:data-source ...

当我部署我的应用程序时,我得到了这个异常:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is 
java.lang.UnsupportedOperationException: Not supported by BasicDataSource
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.UnsupportedOperationException: Not supported by BasicDataSource
    org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
    org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy19.getRecipeList(Unknown Source)
    com.exigen.common.service.RecipeServiceImpl.getRecipeList(RecipeServiceImpl.java:14)
    com.exigen.common.web.HelloController.index(HelloController.java:25)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

java.lang.UnsupportedOperationException: Not supported by BasicDataSource
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1062)
    org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:68)
    org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
    org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
    org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
    org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
    org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
    org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
    org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:59)
    org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
    org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy19.getRecipeList(Unknown Source)
    com.exigen.common.service.RecipeServiceImpl.getRecipeList(RecipeServiceImpl.java:14)
    com.exigen.common.web.HelloController.index(HelloController.java:25)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

我尝试使用谷歌来解决我的问题并将这篇文章作为搜索结果:

https://confluence.atlassian.com/display/CONF28/Fix+'Not+supported+by+BasicDataSource'+Setup+or+Startup+Error

所以似乎我需要在云 tomcat 上进行额外配置,但我无权访问它。

可能是我错过了什么。您能否建议一些解决方案和工作代码示例?

PS 我知道 jdbc 模板,实际上这不是一个好的解决方案,因为我的任务是练习 JPA。

4

3 回答 3

1

如果您的应用程序中只有一种类型的 RDBMS 服务,那么您甚至不需要使用<cloud>命名空间。如果您查看以下文档页面:http ://docs.cloudfoundry.com/frameworks/java/spring/spring.html 并查看“关系数据库(MySQL 和 vFabric Postgres) ”,您可以看到如何自动重新配置作品。

于 2012-07-06T04:34:58.723 回答
0

该解决方案也适用于与云无关的我。我将我的数据源移动到 Tomcat,而不是在应用程序中手动创建它并得到相同的错误。从属性中删除 hibernate.connection.username 和 hibernate.connection.password 有助于解决此问题,如下所述:

修复“BasicDataSource 不支持”设置或启动错误

于 2016-01-25T19:14:24.320 回答
0

将 packagesToScan 添加到您的 EntityManagerFactory 配置中

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.example.domain" />
于 2016-03-09T17:21:58.763 回答