Unable to get the default Bean Validation

按照马士兵的ssh整合视频开始配置ssh架构,但是由于版本不相近遇到了两个问题,特此记录下:

<wbr></wbr>

1.java.lang.NoSuchFieldError: INSTANCEat org.hibernate.type.BasicTypeRegistry.(BasicTypeRegistry.java:94)at org.hibernate.type.TypeResolver.(TypeResolver.java:59)at org.hibernate.cfg.Configuration.(Configuration.java:249)at org.hibernate.cfg.Configuration.(Configuration.java:300)

<wbr></wbr>

<wbr></wbr>

<wbr></wbr>

经过查找发现是hibernate-annotations.jar和hibernate-commons-annotations.jar的问题,hibernate.jar已经将其整合

<wbr></wbr>

<wbr></wbr>

2.去掉两个包之后出现

<wbr></wbr>

Error creating bean with name 'userManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.bolo.examples.dao.base.UserDao com.bolo.examples.service.base.UserManager.userDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in file [E:\MyEclipse9.0\workspace\ssh2\WebRoot\WEB-INF\classes\com\bolo\examples\dao\base\UserDao.class]: Initialization of bean failed; nested exception is 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

<wbr><wbr></wbr></wbr>

也是一番查找之后发现在

<wbr><span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px"><br></span></wbr>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactory<wbr><wbr>Bean"&gt;<br><wbr><wbr><wbr><wbr>&lt;property name="dataSource" ref="dataSource" /&gt;<br><wbr><wbr><wbr><wbr>&lt;property name="hibernateProperties"&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr>&lt;props&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="color:#FF0000; word-wrap:normal; word-break:normal">&lt;prop key="javax.persistence.validation.mode"&gt;none&lt;/prop&gt;<wbr></wbr></span><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr>&lt;/props&gt;</wbr>

<wbr><wbr><wbr><wbr><wbr>&lt;/property&gt;<br><wbr><wbr><wbr><wbr>&lt;property name="packagesToScan" value="com.bolo.examples.entity.*" /&gt;<br><wbr><wbr>&lt;/bean&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr></wbr>

<wbr><wbr></wbr></wbr>

加入红色部分就没有问题了

<wbr style="color:rgb(50,62,50); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(227,235,240)"><span style="color:rgb(50,62,50); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(227,235,240)"></span> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">真是不同的<span style="color:#ED1C24; word-wrap:normal; word-break:normal">版本</span>差异比较大啊</span></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">其实这个问题是我们自己造成的!为什么这么说?因为我们在配置Spring和Hibernate进行结合的时候版本出现了问题。<br> &lt;persistence ...&gt;<wbr><wbr><br><wbr>&lt;persistence-unit ...&gt;<wbr><br><wbr><wbr><wbr>...<wbr><br><wbr><wbr><wbr>&lt;properties&gt;<wbr><br><wbr><wbr><wbr><wbr><wbr>&lt;property name="javax.persistence.validation.mode"<wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>value="callback, ddl"/&gt;<wbr><br><wbr><wbr><wbr>&lt;/properties&gt;<wbr><br><wbr>&lt;/persistence-unit&gt;<wbr><br> &lt;/persistence&gt;<wbr><br><span style="color:#FF0000; word-wrap:normal; word-break:normal">这是hibernate官方文档的一段话!</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">意思就是在hibernate.cfg.xml或者是<br> persistence.xml文件下面需要配置<br> javax.persistence.validation.mode属性!</span></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">特别的!在Hibernate中默认的</span></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">&lt;prop key="javax.persistence.validation.mode"&gt;none&lt;/prop&gt;<br> 是auto而不是none!</span></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; color:rgb(255,0,0)"><span style="color:#000000; word-wrap:normal; word-break:normal">------------------------------------------------------------------------------------------------------------------------------------------</span></span></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="font-size:24px; word-wrap:normal; word-break:normal; line-height:36px">javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包,但是找不到,所以beanvalitionFactory错误。<br> 由于javax.persistence.validation.mode的属性值默认是auto,所以会出错。<br><wbr><br> 在hibernate.cfg.xml里将javax.persistence.validation.mode设置为none,就可以避免出错了。<br><wbr><br><wbr>&lt;!-- Disable the BeanValidation --&gt;<br><wbr>&lt;property name="javax.persistence.validation.mode"&gt;none&lt;/property&gt;</wbr></wbr></wbr></wbr></span></p> <p align="center" style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; color:rgb(255,0,0)"><span style="color:#000000; word-wrap:normal; word-break:normal">------------------------------------------------------------------------------------------------------------------------------------------</span></span></p> <p align="center" style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <wbr></wbr></p> <p align="center" style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; color:rgb(255,0,0)"><span style="color:#000000; word-wrap:normal; word-break:normal"><span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">所以,</span><span style="word-wrap:normal; word-break:normal"><span style="word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">Hibernate 3.6以上版本在用<span style="color:#ED1C24; word-wrap:normal; word-break:normal">junit测试时</span>会提示错误:</span></span></span></span></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-size:14px; background-color:rgb(227,235,240); font-family:'Times new roman'!important"> <span style="word-wrap:normal; word-break:normal; color:rgb(255,0,0)"><wbr></wbr></span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-family:simsun; font-size:14px; background-color:rgb(227,235,240)"> <span style="word-wrap:normal; word-break:normal; color:rgb(229,51,51)"><span style="color:#000000; word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">Unable to get the default Bean Validation factory</span></span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-family:simsun; font-size:14px; background-color:rgb(227,235,240)"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-family:simsun; font-size:14px; background-color:rgb(227,235,240)"> <span style="word-wrap:normal; word-break:normal"><span style="color:#000000; word-wrap:normal; word-break:normal; line-height:30px; font-size:20px">在hibernate.cfg.xml里增加一属性解决:<wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; color:rgb(255,0,0); font-family:'Times new roman'!important"><wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></span></span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-family:simsun; font-size:14px; background-color:rgb(227,235,240)"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-family:simsun; font-size:14px; background-color:rgb(227,235,240)"> <span style="word-wrap:normal; word-break:normal"><span style="color:#000000; word-wrap:normal; word-break:normal; line-height:30px; font-size:20px"><span style="word-wrap:normal; word-break:normal; color:rgb(255,0,0); font-family:'Times new roman'!important"><wbr>&lt;property name="javax.persistence.validation.mode"&gt;none&lt;/property&gt;</wbr></span></span></span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(50,62,50); font-family:simsun; font-size:14px; background-color:rgb(227,235,240)"> <span style="word-wrap:normal; word-break:normal"><span style="color:#000000; word-wrap:normal; word-break:normal; line-height:30px; font-size:20px"><span style="word-wrap:normal; word-break:normal; color:rgb(255,0,0); font-family:'Times new roman'!important"><br></span></span></span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; background-color:rgb(227,235,240)"> <span style="font-family:Times new roman; color:#ff0000"><span style="font-size:20px; line-height:30px">源自:<a target="_blank" href="http://blog.sina.com.cn/s/blog_6ac4c6cb01018rl2.html">http://blog.sina.com.cn/s/blog_6ac4c6cb01018rl2.html</a></span></span></p> </wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值