1. 程式人生 > >分散式開發錯誤彙總

分散式開發錯誤彙總

1. 錯誤一
Error creating bean with name 'helloServiceImpl' defined in class path resource [spring-service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'helloDao' of bean class [www.csdn.spring.service.impl.HelloServiceImpl]: Bean property 'helloDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'helloDao' of bean class
這類錯誤是:一般都是建立了一個dao的spring檔案比如spring-dao建立了一個service的spring檔案,在spring-service.xml中引用dao的中定義的id名,導致的錯誤,疏忽是:寫service實現類的時候忘記了寫對應dao的setter方法,即所謂的依賴注入
比如:
  private HelloDao helloDao;
  
   //set依賴注入很重要,不寫會報錯,不能讀寫helloDao這一屬性
   publicvoid setHelloDao(HelloDao helloDao) {
      System.out
      .println("控制反轉:應用程式本身不在負責建立helloDao物件,而是由spring容器負責建立、管理、維護,這樣控制權轉移,稱為反轉。"
            + "可以通過依賴注入方式注入該HelloDao物件");
      this.helloDao = helloDao;
   }
2. 錯誤二
Configuration problem: Failed to import bean definitions from relative location [spring-dao.xml]Offending resource: class path resource [spring.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from class path resource [spring-dao.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Open quote is expected for attribute "{1}" associated with an  element type  "scope".
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from class path resource [spring-dao.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Open quote is expected for
Caused by: org.xml.sax.SAXParseException: Open quote is expected for attribute "{1}" associated with an  element type  "scope".
這種錯誤是馬虎的錯誤,在對應的spring的配置檔案中,bean標籤的scope屬性忘了加引號,在配置檔案中國不會報錯,但是在執行的時候就會出這樣的錯,一般導致錯誤的原因是複製的時候疏忽了引號,直接將原來的引號覆蓋了,導致了最後該屬性沒有引號。
<bean id="helloDaoImpl" class="www.csdn.spring.dao.impl.HelloDaoImpl"
    scope="prototype"></bean>
錯誤的寫成:
bean id="helloDaoImpl" class="www.csdn.spring.dao.impl.HelloDaoImpl"
      scope=prototype></bean>
3. 錯誤
No bean named 'helloServiceImp' is defined
       at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition
   這種報錯但是沒Caused by語句的錯誤一般都是使用的時候單詞寫錯了,這裡寫錯的地方是在java類中,類中引用id的時候寫錯了單詞;比如這裡的錯,注意下面的紅色文字:
HelloService helloService2 = (HelloService) context.getBean("helloServiceImp",HelloServiceImpl.class);
     <bean id="helloServiceImpl" class="www.csdn.spring.service.impl.HelloServiceImpl" scope="singleton" lazy-init="false">
       <property name="helloDao" ref="helloDaoImpl"/>
     </bean>
  眼尖的哥們估計都看出來了這兩個單詞寫的不一樣,獲取bean的方法中引用的id少寫了一個“i”,導致spring容器在讀取的時候不能識別。以後注意細心就好。
4. 錯誤四
Error creating bean with name 'helloServiceImpl' defined in class path resource [spring-service.xml]: Cannot resolve reference to bean 'helloDaoImp' while setting bean property 'helloDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'helloDaoImp' is defined
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'helloDaoImp' is defined
       at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition
   這種也是單詞寫錯的情況,與上面不同的是這種情況給出了Caused by語句,讓你更清楚錯誤發生的原因,英文還差不多的哥們或者一定程式設計經驗的人員一看Caused by語句就應該能判斷出什麼錯誤;這裡錯誤原因明顯才、指出每一個名字為'helloDaoImp'的bean,或名字為'helloDaoImp'的bean未定義,這種錯也好好找,一般都是互相引用的spring配置檔案馬虎出的錯,下面一個例子說明:比如spring-service.xml引用spring-dao的時候,還是如上面說的一樣,重點再紅色字型
  Service配置檔案中這麼寫:
  <bean id="helloServiceImpl" class="www.csdn.spring.service.impl.HelloServiceImpl" scope="singleton" lazy-init="false">
       <property name="helloDao" ref="helloDaoImp"/>
     </bean>
但是dao配置檔案中卻這麼寫:
bean id="helloDaoImpl" class="www.csdn.spring.dao.impl.HelloDaoImpl"
      scope="prototype"></bean>
   寫到這大家就清楚了吧,與上一個錯誤基本上一樣,都是單詞寫錯的錯誤,只不過不同的是上一個錯誤是在java類中引用id的時候寫錯單詞出的錯,而這一個錯誤是在spring配置檔案中國引用id出的錯,萬變不離其宗,錯誤的額原因都是單詞寫錯,今後細心即可。
5. 錯誤五
Cannot find class [www.csdn.spring.dao.imp.HelloDaoImpl] for bean with name 'helloDaoImpl' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException:www.csdn.spring.dao.imp.HelloDaoImpl
   Caused by: java.lang.ClassNotFoundException: www.csdn.spring.dao.HelloDaoImpl
   錯誤原因:倒錯包了,我的web專案HelloDaoImpl在dao.impl包下而不是dao包下。所以包這樣的錯,看一下spring配置文具店額classes標籤的值匯入的類包名是否正確
6. 錯誤六
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeBean' defined in class path resource [spring-constructor.xml]: Unsatisfied dependency expressed through constructor argument with index 2 of type [double]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?
  錯誤原因:bean例項類中的屬性型別與spring配置檔案中的構造器屬性型別不對應所導致,這種情況多出在使用型別指定構造器引數;比如:
  類中屬性如下,重點注意紅色部分:
   private String name;
   private String sex;
   private doublesalary;
  spring配置檔案中的構造器標籤
<constructor-arg type="java.lang.String" value="楊凱" />
<constructor-arg type="java.lang.String" value="男" />
<constructor-arg type=" java.lang.Double" value="5000.00" />
  這種錯誤是因為構造器中的type屬性不會自動對應拆箱裝箱屬性型別,簡單點說就是類中使用的是基本資料型別,配置檔案中對應的type屬性值就要是基本資料型別;類中使用的是類型別,配置檔案中對應的type屬性值就要是包名加上類型別;
   還一種原因就是不對應的原因,constructor-arg直接寫錯了,比如:private doublesalary;對應了<constructor-arg type=" Double" value="5000.00" />
  或者順序不對的情況下回出現賦值錯誤,比如同時存在兩個相同型別的屬性,name應該為“楊凱”,如果sex在配置檔案的位置與name的顛倒了,會出現name=“男”的情況
7. 錯誤七
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberBean' defined in class path resource [spring-construtor.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'www.csdn.spring.constructor.Member' for property 'member'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [www.csdn.spring.constructor.Member] for property 'member': no matching editors or conversion strategy found
   Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'www.csdn.spring.constructor.Member' for property 'member'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [www.csdn.spring.constructor.Member] for property 'member': no matching editors or conversion strategy found
   錯誤原因:這種情況是一個bean例項引用另一個bean例項物件,而引用的那個bean例項物件為空,但是在改bean例項的配置檔案中又錯誤指明空值。舉個例子說明:
<bean id="memberBean" class="www.csdn.spring.constructor.MemberBean">
      <!-- value="null" 這裡給value賦的是一個空字串,而不是一個null空值 -->
      <property name="name" value="null"/>
      <property name="member">
        <null/>
      </property>
   </bean>
   關鍵看紅色部分,紅色部分是正確的寫法,這樣寫引用空值物件才不會報錯,但是如果你像上面引用nam屬性那樣指明value=“null”就會出現改錯。
8. 錯誤八
   錯誤一:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Bean name 'deptBean' is already used in this <beans> element
Offending resource: class path resource [spring-byType.xml]
   錯誤二:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empBean' defined in class path resource [spring-byType.xml]: Unsatisfied dependency expressed through bean property 'deptBean': : No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean,deptBean1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean,deptBean1
   Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean,deptBean1
   這兩種錯誤原因:都是spring配置檔案中自動裝配按byType時出的問題,配置檔案, 紅色部分為錯誤的解釋和導致錯誤的原因如下:
       <bean id="compBean" class="www.csdn.spring.autowire.CompBean">
         <property name="name" value="DELL"/>
       </bean>
      
       <bean id="deptBean" class="www.csdn.spring.autowire.DeptBean">
         <property name="name" value="銷售部門"/>
       </bean>
       <!--
          這裡只能出現一個deotBean,id名不一樣但是型別一樣,都是deptBean實體的;id="deptBean"或同類型的不同id都會拋異常
       <bean id="deptBean1" class="www.csdn.spring.autowire.DeptBean">
         <property name="name" value="銷售部門"/>
       </bean> -->
      
       <!-- 使用autoWrie自動裝配,改屬性值byType;
                    型別自動裝配,前提是同一個型別的只能有一個-->
                   
       <bean id="empBean" class="www.csdn.spring.autowire.EmpBean" autowire="byType">
          <property name="name" value="楊凱"/>
<!--           <property name="comp" ref="compBean"/>
          <property name="dept" ref="deptBean"/> -->
       </bean>
 9. 錯誤九
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empBean' defined in class path resource [spring-byConstructor.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [www.csdn.spring.autowire.DeptBean]: : No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean1,deptBean2; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean1,deptBean2
       at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray
    Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean1,deptBean2
    錯誤原因: spring配置檔案中自動裝配按constructor時出的問題,配置檔案, 紅色部分為錯誤的解釋和導致錯誤的原因如下:
       <!-- 在spring3.2以上版本中:使用構造器自動裝配時,如果一個id與bean例項中的屬性名相同的配置bean存在,雖然構造器自動裝配是型別自動裝配的,
             但是即使多個相同型別的bean存在也不受影響;受影響的情況是:沒與bean例項中的屬性名相同的配置bean存在,
             又多個相同型別的bean配置,就會拋異常-->
       <bean id="deptBean" class="www.csdn.spring.autowire.DeptBean">
         <property name="name" value="銷售部門"/>
       </bean>
      
       <bean id="deptBean1" class="www.csdn.spring.autowire.DeptBean">
         <property name="name" value="銷售部門"/>
       </bean>
 
       <bean id="deptBean2" class="www.csdn.spring.autowire.DeptBean">
         <property name="name" value="銷售部門"/>
       </bean>
      
       <!-- 使用autoWrie自動裝配,改屬性值constructor;構造器自動裝配就是型別自動裝配
                    beam例項中必須結合構造器使用,如果沒構造器自動裝配後注入不進去值,取出為空值-->
                   
       <bean id="empBean" class="www.csdn.spring.autowire.EmpBean" autowire="constructor">
          <property name="name" value="楊凱"/>
<!--           <property name="comp" ref="compBean"/>
          <property name="dept" ref="deptBean"/> -->
       </bean>
10. 錯誤十
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure
during bean definition parsing
Offending resource: class path resource [spring-collection.xml]
Bean 'collectionBean'; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: <property> element for property 'users' must specify a ref or value
Offending resource: class path resource [spring-collection.xml]
Bean 'collectionBean'
       -> Property 'users'
    Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: <property>
element for property 'users' must specify a ref or value
Offending resource: class path resource [spring-collection.xml]
Bean 'collectionBean'
       -> Property 'users'
     乍一看,有些許沒有頭腦,但是放下心仔細看看,提示說什麼users屬性怎麼怎麼滴;還有一點提示就是說是spring-collection.xml配置檔案中的錯誤,這就好找,找到改配置中有關users的地方,
<bean id="u1" class="www.csdn.spring.collection.set.User">
      <property name="name" value="楊凱" />
      <property name="age" value="22" />
   </bean>
。。。。。
     這樣的程式碼肯定不會出錯了,如果是這裡的錯報的就不是這個錯了,可能就是第一條或第二條錯了;再找下一塊有users的地方,找到了這裡:
<!-- list集合 -->
      <property name="users">
         <!-- <array>
            <ref bean="u1" />
            <ref bean="u2" />
            <ref bean="u3" />
         </array> -->
         <!-- <list>
         <ref bean="u1"/>
         <ref bean="u2"/>
         <ref bean="u3"/>
         </list> -->
        
         <!-- 還可以通過spring自帶的sehema約束中的util工具約束的list集合遍歷-->
         <util:list>
            <ref bean="u1" />
            <ref bean="u2" />
            <ref bean="u3" />
         </util:list>
        
      </property>
     仔細一看真是這裡的錯,紅色部分最開始忘了寫,註釋掉了上面的list注入值的方式,後面的uti標籤注入值有沒有寫,這是在測試類中取值遍歷的時候就會遍歷一個空的users,這是因為是沒有注入值的錯,所以沒有報空指標的錯,報的是這種莫名其妙的錯。
11. 錯誤十一
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'proxyFactoryBean' must be of type [www.csdn.spring.advice.SayServiceImpls], but was actually of type [$Proxy4]
    這種錯誤一般出在aop面向切面的程式設計中,spring面向切面的代理有兩種,一種是jdk動態代理,一種是cglib代理;這是你在使用的的使用如果混合時候就會出現上面的錯;這兩種代理的區別是前者是介面代理,就是返回一個介面型別物件,而後者是類代理,不能返回介面型別物件只能返回類型別物件,如果返回介面了同樣會出這樣的錯。
   還有可能出錯的地方就是對應的spring配置檔案,這
裡是最容易馬虎出錯的地方,仔細檢查一下的你的目標物件,比如:<!-- 目標物件 -->
    <property name="target">
      <ref bean="sayServiceImpls"/>
    </property>
   這裡在引用bean的時候可能引入錯誤,可能會引入jdk動態代理的目標類,也有可能你的目標類中實現了某些介面,不符合cglib代理的理念;還有可能馬虎出錯的地方:
<!-- 真實主題   目標物件 -->
  <bean id="sayServiceImpls" class="www.csdn.spring.advice.SayServiceImpls"></bean>
   真實物件的id和class屬性設定錯誤的時候也會出錯。
12. 錯誤十二
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'proxyFactoryBean' defined in class path resource [spring-advice.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'proxyInterfaces' threw exception; nested exception is java.lang.IllegalArgumentException: [www.csdn.spring.proxy.advice.SayServiceImpl] is not an interface
    Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'proxyInterfaces' threw exception; nested exception is java.lang.IllegalArgumentException: [www.csdn.spring.proxy.advice.SayServiceImpl] is not an interface
   這個問題很好解決,最關鍵的問題出在紅色部分,原因是在spring相關配置檔案中設定抽象主題的時候,既然是抽象主題就應該設定成介面,而不應該是實現類。比如下面的程式碼,注意紅色部分:
  <!--抽象主題   實現介面 -->
    <property name="proxyInterfaces">
      <array>
     <value>www.csdn.spring.proxy.advice.SayServiceImpl</value>
      </array>
    </property>
   正確的寫法應該是:
  <!--抽象主題   實現介面 -->
    <property name="proxyInterfaces">
      <array>
        <value>www.csdn.spring.proxy.advice.SayService</value>
      </array>
    </property>
13. 錯誤十
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'proxyFactoryBean': FactoryBean threw exception on object creation; nested exception is org.springframework.aop.framework.AopConfigException: Unknown advisor type class www.csdn.spring.proxy.advice.AuditableImpl; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry,which may also be target or TargetSource; nested exception is org.springframework.aop.framework.adapter.UnknownAdviceTypeException: Advice object [
[email protected]
] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor]
    Caused by: org.springframework.aop.framework.AopConfigException: Unknown advisor type class www.csdn.spring.proxy.advice.AuditableImpl; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry,which may also be target or TargetSource; nested exception is org.springframework.aop.framework.adapter.UnknownAdviceTypeException: Advice object [
[email protected]
] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor]
   這個錯誤即紅色部分提示的錯誤,不知道advice型別的異常,說白了就是編寫的spring通知的錯誤,這種錯誤比較常見,也是出於馬虎的錯誤,比如前者通知、後置通知、環繞通知、異常通知、引入通知等這幾個通知中的任何一個通知類忘了寫繼承的父類;以下列出這幾個通知的類編寫所繼承的類:
    前置通知:
public class BeforeAdvice implements MethodBeforeAdvice
    後置通知:
public class AfterAdvice implements AfterReturningAdvice
       環繞通知:
public class AroundAdvice implements MethodInterceptor
       異常通知:
public class ThrowAdvice implements ThrowsAdvice
       引入通知:
public class AuditableImpl extends DelegatingIntroductionInterceptor implements Auditable
14. 錯誤十四
java.lang.ClassCastException:
$Proxy10 cannot be cast to www.csdn.spring.proxy.advice.Auditable
java.lang.ClassCastException:
$Proxy11 cannot be cast to www.csdn.spring.proxy.advice.Auditable
    像以上這個出現$ProxyXX cannot be cast to www.csdn.spring.proxy.advice.Auditable;什麼代理不能強轉成某一個型別的錯誤,一般都是在使用JDK動態代理或cglib代理的時候出現的錯誤,錯誤原因有:
    1).JDK動態代理與cglib代理混淆,比如使用cglib代理時不能實現介面,你可能在使用的時候使用了cglib代理,但是卻實現了介面,如果你在spring配置檔案中使用aspectjs來進行通知,又想使用cglib介面那麼你需要做的是目標類不實現介面,spring配置檔案中配置aop的時候加上下面紅色部分。
<aop:aspectj-autoproxyproxy-target-class="true"/>
   2)同樣是使用aspectjs通知的時候,尤其是使用引入通知的時候,一定不要忘了讓引用通知的業務類加上註解@Aspect;還要注意的是你使用的引入目標類和其實現介面的類路徑一定要正確,我這裡就範了一個小錯誤,到錯包的錯:
package www.csdn.spring.proxy.advice.aspectjs;
 
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
 
@Aspect
publicclass AuditableService {
 
   @DeclareParents(value="*..*Service*", defaultImpl = AuditableImpl.class)
   public Auditable auditable;
}
   我在使用Auditable介面的時候倒錯了包,這裡其實類都在同一包下,根本不用倒包,但是我從上一個包中複製程式碼的時候自動給我引入了上一個包的Auditable類;以後一定要注意了
15. 錯誤十五
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: <aspect> tag needs aspect bean reference via 'ref' attribute when declaring advices.
Offending resource: file [F:\csdn-study\MyWorkspace\springHelloJava\bin\spring-pojoXmlAspectjs.xml]
Aspect: ref=''
   這個錯誤顧名思義,這裡已經提示的很清了,這裡列出這個錯誤是對那些對pojo-xml配置通知不太熟悉的同學而言;這個錯誤就是在對應的spring配置檔案中使用aop切面的時候忘寫了一個ref熟悉的錯,具體案例程式碼如下,注意下面的紅色部分,錯誤就出在紅色部分忘了寫ref="adviceService":
   <!-- 使用pojo-xml aspectjs配置自動代理 -->
   <aop:config>
  
      <!-- 配置切面 -->
      <aop:aspect ref="adviceService">
     
         <!-- 引入通知 -->
         <aop:declare-parents types-matching="*..*Service*"
            implement-interface="www.csdn.spring.proxy.advice.aspectjs.pojoxml.Auditable"
            default-impl="www.csdn.spring.proxy.advice.aspectjs.pojoxml.AuditableImpl" />
 
         <!-- 切面切入的位置切入點,可以同時寫多個不同的切入點 -->
         <aop:pointcut expression="execution(* www.csdn..UserServiceImpl.save(..))"
            id="myPcut" />
         <aop:pointcut expression="execution(* www.csdn..UserServiceImpl.update(..))"
            id="myPcuts" />
 
         <!--織入通知 method:指明方法; pointcut-ref引入切入點 -->
         <aop:before method="beforeMethod" pointcut-ref="myPcut" />
         <aop:after method="afterMethod" pointcut-ref="myPcut" />
         <aop:around method="aroundMethod" pointcut-ref="myPcuts" />
        
      </aop:aspect>
     
   </aop:config>
16. 錯誤十六
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deptDaoImpl' defined in class path resource [spring-dao.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
   關鍵是藍色部分,藍色部分已經給出了提示:不匹配的構造器,這種錯誤出在spring配置中,使用namedParameterJdbcTemplate時出的錯,錯誤出在下面:
   <bean id="namedParameterJdbcTemplate"
   class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
      <property name="namedParameterJdbcTemplate" ref="namedParameterJdbcTemplate" />
   </bean>
正確寫法:
   <bean id="deptDaoImpl" class="www.csdn.spring.jdbc.DeptDaoImpl">
      <property name="namedParameterJdbcTemplate" ref="namedParameterJdbcTemplate" />
   </bean>
    由於對該類不理解或者複製時容易出這樣的錯誤
17. 錯誤十七
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'localSessionFactoryBean' defined in class path resource [spring-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
   Caused by: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
     這裡根據提示說錯誤的原因是當資料庫不能連線的時候,需要配置hibernate.dialect'就是hibernate配置的方言,原因出在驅動類的配置,比如:properties檔案中的:hibernate.driverClassName=oracle.jdbc.driver.OracleDriver
這裡如果寫錯了就會出現不能連線的情況,驅動的名字一定要正確,配置檔案中的其他屬性也一定要正確,據我本人測試如果在改配置檔案中直接寫的driverClassName=oracle.jdbc.driver.OracleDriver
在spring配置檔案這樣取值時:<property name="driverClassName" value="${driverClassName}" />就會錯誤,但是如果這樣寫就對:<property name="driverClassName" value="${hibernate.driverClassName}" />
18. 錯誤十八
java.lang.IllegalArgumentException: node to traverse cannot be null!
     解決方法:通常此類錯誤都是由於HQL語句寫的不正確,例如from寫成了form,或者set A = 1 and B = 2,其中set不同欄位用逗號","分離而不是用and.總之仔細檢查HQL語句,看看有沒有語法錯誤即可.