2013-05-28 57 views
0

我有一個問題,這個程序Spring MVC中沒有默認構造函數發現

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cdmiService': Cannot resolve reference to bean 'badRequestException' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'badRequestException' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.snia.cdmiserver.exception.BadRequestException]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.snia.cdmiserver.exception.BadRequestException.<init>() 

和我的XML如下:

<bean id="badRequestException"  class="org.snia.cdmiserver.exception.BadRequestException"/> 

的BadRequestException.java如下:

public class BadRequestException extends RuntimeException { 
public BadRequestException(String message) { 
    super(message); 
} 

public BadRequestException(String message, Throwable cause) { 
    super(message, cause); 
} 

public BadRequestException(Throwable cause) { 
    super(cause); 
} 

我該如何解決這個問題?添加一個默認的建築師或編輯XML文件?

+2

最有趣的事情在這裏:你爲什麼要創建一個異常類豆? –

回答

0

我該如何解決這個問題?添加一個默認的構造函數或編輯xml文件?

你可以解決它。

  1. 添加默認construtor:

    public BadRequestException() { 
         super(); 
        } 
    
  2. 編輯XML文件

    <bean id="badRequestException"  class="org.snia.cdmiserver.exception.BadRequestException"> 
        <constructor-arg type="java.lang.String"><value>Message you want</value></constructor-arg> 
    </bean > 
    
相關問題