欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java编程ssh整合常见错误解析

程序员文章站 2024-04-03 18:04:46
1. org.springframework.transaction.cannotcreatetransactionexception: could not open jp...

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.<init>(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

原因:项目使用了<context:component-scan/>扫描机制, 而类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中使用了<constant name="struts.objectfactory" value="spring"/>,将其注释掉

总结

以上就是本文关于java编程ssh整合常见错误解析的全部内容,希望能对大家有所帮助。如有不足之处,欢迎留言指出,小编会及时更正。感兴趣的朋友可以参阅:kryo框架使用方法代码示例java集合框架源码分析之linkedhashmap详解浅谈zookeeper开源客户端框架curator等以及本站其他相关专题,感谢大家对本站的支持!