Struts2.2.3 + Spring3.0 +Hibernate 3.6.8整合的时候,
报如下异常:
[cc lang="java"]Exception in thread "main" 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$1.getObject
(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory
.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory
.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory
.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext
.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext
.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support
.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support
.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:84)
at cn.chenl.ssh.app.test.TestDao.main(TestDao.java:12)
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:1704)
at org.hibernate.cfg.Configuration
.applyConstraintsToDDL(Configuration.java:1654)
at org.hibernate.cfg.Configuration
.secondPassCompile(Configuration.java:1445)
at org.hibernate.cfg.Configuration
.buildMappings(Configuration.java:1375)
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)
... 12 more[/cc]
原因,可能是hibernate版本过高的问题
解决办法,修改配置文件:
[cc lang="xml"]
org.hibernate.dialect.MySQLDialect
nonecn.chenl.ssh.app.entity.Student
[/cc]
加入none
或者修改maven (参考:http://stackoverflow.com/questions/6054692/error-creating-bean-sessionfactory) :
[cc lang="xml"]javax.validationvalidation-api1.0.0.GAorg.hibernatehibernate-validator4.0.2.GA
[/cc]