Spring MVC没有找到默认构造函数

时间:2013-05-28 10:50:27

标签: spring cxf

我的这个程序有问题

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);
}

如何解决此问题?添加默认construtor或编辑xml文件?

1 个答案:

答案 0 :(得分:0)

  
    

如何解决此问题?添加默认construtor或编辑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 >