登录  /  注册
首页 > Java > java教程 > 正文

Java之ssh整合常见错误的解决

黄舟
发布: 2017-10-17 09:34:03
原创
2511人浏览过

这篇文章主要介绍了java编程ssh整合常见错误解析,如果有什么不足之处,欢迎留言补充。

1. org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.UnsupportedOperationException: Not supported by BasicDataSource

Spring不能为JAP创建事务。原因是bean.xml设定了数据源persistence.xml中要把数据库连接去掉


<property name="hibernate.connection.username" value="xxx"/>
<property name="hibernate.connection.password" value="xxx"/> 
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/xxx? useUnicode=true&characterEncoding=UTF-8"/>
登录后复制

2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productServiceBean': Injection of persistence fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(childtypes)]

原因:@Id @GeneratedValue(strategy = GenerationType.AUTO)

这个注解写在get方法上不要写在属性声明上。

3. javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not insert: [com.yufei.bean.product.ProductType]
Caused by: java.sql.SQLException: Data too long for column 'visible' at row 1

原因:实体类字段中的visible插入到数据库中所对应的值为ASCII码味49,超出范围。

换个mysql的jar包解决问题。

4. web容器出现

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

此问题多样化,查阅资料说是jar包commons-logging.jar问题 ,但解决的方式是重新导入项目...

5. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productTypeService': Injection of persistence fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V

原因: Spring2.5下asm-2.2.3.jar 与hibernate下的asm.jar 冲突, 删除asm-2.2.3.jar 。

6. Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:340)

原因:lib中缺少standard.jar , jstl.jar

7. java.lang.NoSuchFieldError: DIRECTORY
at net.fckeditor.connector.impl.AbstractLocalFileSystemConnector.getFolders(AbstractLocalFileSystemConnector.java:140)
at net.fckeditor.connector.Dispatcher.getFoldersAndOrFiles(Dispatcher.java:204)
at net.fckeditor.connector.Dispatcher.doGet(Dispatcher.java:156)
at net.fckeditor.connector.ConnectorServlet.doGet(ConnectorServlet.java:89)

原因:包冲突,删掉struts1.3自带的commons-io-1.1.jar,commons-fileupload-1.1.1.jar,加入commons-io-1.3.2.jar,commons-fileupload-1.2.1.jar

8.IOException while loading persisted sessions: java.io.EOFException
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2281)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2750)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
at java.io.ObjectInputStream.(ObjectInputStream.java:280)

原因是tomcat对硬盘的session读取失败,彻底解决办法一下:将work下面的文件清空,主要是*.ser文件,或者只是删除掉session.ser即可以解决。

9.javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.dalton.domain.User
org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException

原因:

(1) 是entity bean的 @Id标记错了,标记在了String 等类型上
(2) 对id字段手工设定了值。

10 org.springframework.web.context.ContextLoader(line:215) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'brand' defined in file [D:\Tomcat6\webapps\autoet\WEB-INF\classes\com\autoet\
action\brand\BrandAction.class]: Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate bean
class [com.autoet.action.brand.BrandAction]: Constructor threw exception; nested
exception is java.lang.NullPointerException

原因:项目使用了扫描机制, 而类BrandAction没有标注为原型,
为类添加 @Scope("prototype")标注(与@Controller相同位置)

11 org.hibernate.tool.hbm2ddl.SchemaUpdate(line:222) - could not complete schema update
java.lang.UnsupportedOperationException: Not supported by BasicDataSource

原因 spring.xml 与 persistence.xml中都配置了数据库连接,注释掉persistence.xml中的连接信息

12 org.apache.struts2.dispatcher.Dispatcher(line:27) - Dispatcher initialization failed
Unable to load configuration. - [unknown location]
Cannot locate the chosen ObjectFactory implementation: spring - [unknown location]

原因 struts.xml中使用了,将其注释掉

总结

以上就是Java之ssh整合常见错误的解决的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号