spring常見錯誤總結:

1.Caused by: org.springframework.beans.NotWritablePropertyException:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property ‘runner’ of bean class [com.dao.AccountDaoImpl]: Bean property ‘runner’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

意思是在com.dao.AccountDaoImpl中缺少屬性runner的setter方法。
或者說是setter方法不符合駝峯命名。

2.java.sql.SQLException: No suitable driver
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
原因(1) 很有可能這下面的數據錯了

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <!--連接數據庫的必備信息-->
    <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
    <property name="jdbcUrl" value="jdbc:mysql//localhost:3306/Zzz"></property>
    <property name="user" value="root"></property>
    <property name="password" value="123456"></property>
</bean>

我的就是jdbc:mysql:// 少了一個冒號。
(2)還有一個也就是字面意思:你沒有適用的驅動

3、Exception in thread “main” org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 37 in XML document from class path resource [bean.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 84; cvc-complex-type.2.4.a: 發現了以元素 ‘aop:pointcut’ 開頭的無效內容。應以 ‘{“http://www.springframework.org/schema/aop”:aspect}’ 之一開頭。
Caused by: org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 84; cvc-complex-type.2.4.a: 發現了以元素 ‘aop:pointcut’ 開頭的無效內容。應以 ‘{“http://www.springframework.org/schema/aop”:aspect}’ 之一開頭。
Spring xml中導的約束規定切入點表達式必須寫在切面前。

4、Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘service’ defined in class path resource [bean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.Service]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.Service.()
Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘service’ defined in class path resource [bean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.Service]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.Service.()

問題所在:用XML創建bean對象時,用的是默認構造函數,但是此時如果類中沒有默認構造函數

發佈了33 篇原創文章 · 獲贊 1 · 訪問量 4709
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章