首頁  >  文章  >  Java  >  Java之ssh整合常見錯誤的解決

Java之ssh整合常見錯誤的解決

黄舟
黄舟原創
2017-10-17 09:34:032755瀏覽

這篇文章主要介紹了Java程式設計ssh整合常見錯誤解析,如果有什麼不足之處,歡迎留言補充。

1. org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.UnsupportedOperationException: Not ported by#supSourceported by#supSource.
##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.Factorcnation inception class reception name. [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: [orgpingnatenate. (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容器出現

#Fall: 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]: Invoid of inucht. : 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.crr.compiler 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.javaLocalFileSystemConnector.getFolders(AbstractLocalFileSystemConnector.javaLocalFileSystemConnector.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.conn。 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)##2750)at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
at java.io.ObjectInputStream.7e51f00a783d7eb8f68358439dee7daf(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#fexception orception.

原因:專案使用了4c768a35efd9b5c69daed3835397d811掃描機制, 而類別BrandAction沒有標註為原型,為類別添加@Scope("prototype" )標註(與@Controller相同位置)

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

#原因spring.xml 與persistence.xml中都配置了資料庫連線,註解掉persistence.xml中的連線資訊

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

##原因struts.xml中使用了24ad0ab83c573ec5304a5620b7bb24c1 ,將其註解掉

總結#

以上是Java之ssh整合常見錯誤的解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn