按照马士兵的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"><br><wbr><wbr><wbr><wbr><property name="dataSource" ref="dataSource" /><br><wbr><wbr><wbr><wbr><property name="hibernateProperties"><br><wbr><wbr><wbr><wbr><wbr><wbr><props><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><prop key="hibernate.show_sql">true</prop><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><prop key="hibernate.format_sql">true</prop><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="color:#FF0000; word-wrap:normal; word-break:normal"><prop key="javax.persistence.validation.mode">none</prop><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></props></wbr>
<wbr><wbr><wbr><wbr><wbr></property><br><wbr><wbr><wbr><wbr><property name="packagesToScan" value="com.bolo.examples.entity.*" /><br><wbr><wbr></bean></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> <persistence ...><wbr><wbr><br><wbr><persistence-unit ...><wbr><br><wbr><wbr><wbr>...<wbr><br><wbr><wbr><wbr><properties><wbr><br><wbr><wbr><wbr><wbr><wbr><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"/><wbr><br><wbr><wbr><wbr></properties><wbr><br><wbr></persistence-unit><wbr><br> </persistence><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"><prop key="javax.persistence.validation.mode">none</prop><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><!-- Disable the BeanValidation --><br><wbr><property name="javax.persistence.validation.mode">none</property></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><property name="javax.persistence.validation.mode">none</property></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>