spring整合hibernate出现HibernateException: Unable to get the default Bean Validation factory
来源:互联网 发布:淘宝店运营商靠谱吗 编辑:程序博客网 时间:2024/05/17 08:22
我的xml配置如下:
- <?xml version=“1.0” encoding=“UTF-8”?>
- <beans xmlns=“http://www.springframework.org/schema/beans”
- xmlns:context=“http://www.springframework.org/schema/context” xmlns:tx=“http://www.springframework.org/schema/tx”
- xmlns:aop=“http://www.springframework.org/schema/aop” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
- xsi:schemaLocation=”http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.0.xsd”>
- <import resource=“classpath:beans.xml” />
- <context:property-placeholder location=“jdbc.properties” />
- <!– springJdbc –>
- <bean id=“dataSource” class=“org.apache.commons.dbcp.BasicDataSource”
- destroy-method=“close”>
- <property name=“driverClassName” value=“{jdbc.driverClassName}"</span><span> </span><span class="tag">/></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">property</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"url"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"{jdbc.url}” />
- <property name=“username” value=“{jdbc.username}"</span><span> </span><span class="tag">/></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">property</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"password"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"{jdbc.password}” />
- </bean>
- <bean id=“sessionFactory”
- class=“org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
- <property name=“dataSource” ref=“dataSource” />
- <property name=“hibernateProperties”>
- <value>
- hibernate.dialect=org.hibernate.dialect.MySQLDialect
- hibernate.show_sql=true
- hibernate.hbm2ddl.auto=update
- </value>
- </property>
- <property name=“mappingResources”>
- <array>
- <value>com/xiaohui/domain/User.hbm.xml</value>
- </array>
- </property>
- </bean>
- <!– 配置事务管理器 –>
- <bean id=“transactionManager”
- class=“org.springframework.orm.hibernate3.HibernateTransactionManager”>
- <property name=“sessionFactory” ref=“sessionFactory”></property>
- </bean>
- <tx:annotation-driven transaction-manager=“transactionManager” />
- </beans>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <import resource="classpath:beans.xml" /> <context:property-placeholder location="jdbc.properties" /> <!-- springJdbc --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.hbm2ddl.auto=update </value> </property> <property name="mappingResources"> <array> <value>com/xiaohui/domain/User.hbm.xml</value> </array> </property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager" /></beans>
错误信息如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to get the default Bean Validation factory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1420)
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
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.HibernateException: Unable to get the default Bean Validation factory
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:127)
at org.hibernate.cfg.Configuration.applyBeanValidationConstraintsOnDDL(Configuration.java:1674)
at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1624)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1415)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
… 34 more
Caused by: java.lang.reflect.InvocationTargetException
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.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:118)
… 42 more
Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:345)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:106)
… 47 more
Caused by: javax.validation.ValidationException: Unable to instantiate Configuration.
at javax.validation.Validation
… 50 more
查了好久好久,最后发现找到的答案是:在sessionFactory的hibernateProperties属性中要在家上这样一个键值对!
javax.persistence.validation.mode=none
- spring整合hibernate出现HibernateException: Unable to get the default Bean Validation factory
- spring整合hibernate出现HibernateException: Unable to get the default Bean Validation factory
- HibernateException:Unable to get the default Bean Validation factory
- hibernate 错误:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- hibernate 错误:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- hibernate :org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- 【转】hibernate 错误:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- 1. hibernate 错误:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- hibernate 错误:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- hibernate 错误:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- hibernate 错误:org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- hibernate和spring整合:Unable to get the default Bean Validation factory
- org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- 异常解决—org.hibernate.HibernateException: Unable to get the default Bean Validation factory
- Hibernate异常: Unable to get the default Bean Validation factory
- Spring与Hibernate整合报错:unable to get the default bean validation
- hdoj 1072 Nightmare 广搜
- 猴子吃桃问题
- 常用 SQL Server 规范集锦
- JAVA面向对象易错习题详解
- hibernate学习笔记一
- spring整合hibernate出现HibernateException: Unable to get the default Bean Validation factory
- HDU
- Servlet--Session创建时间
- 组织工程
- P2161 [SHOI2009]Booking 会场预约
- HPUX常用核心参数配置说明
- Unix socket进程间通信
- 翻译:AVPlayerItemVideoOutput
- 读Zepto源码之Callbacks模块