java - LazyList.decorate - 实例化工厂 : The constructor must exist and be public exception

标签 java spring spring-mvc

我有那个代码:

public class User   
...
private List<Country> countries = LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(Country.class));
    private String country;

...
public void setCountries(List<Country> countries) {
        this.countries = countries;
    }

    public List<Country> getCountries() {
        return countries;
    }
...

在国家级:

public class Country {

    private int countryId;
    private String countryName;

    public Country(int countryId, String countryName)
    {
        this.countryId = countryId;
        this.countryName = countryName;
    }

    public int getCountryId() {
        return countryId;
    }

    public void setCountryId(int countryId) {
        this.countryId = countryId;
    }

    public String getCountryName() {
        return countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }

}

当我创建一个新的用户对象时,我给出了这个异常:

java.lang.IllegalArgumentException: InstantiateFactory: The constructor must exist and be public

有人知道为什么吗?

最佳答案

似乎您拥有的唯一构造函数是:

public Country(int countryId, String countryName)

虽然工厂期望找到no-arg 构造函数(常见要求):

public Country()

将它添加到您的 Country 类中,您会没事的。

关于java - LazyList.decorate - 实例化工厂 : The constructor must exist and be public exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5043005/

相关文章:

java - Spring MVC - 当休息 Controller 响应类型为空时自动返回 204

java - 单元测试时如何设置全局环境变量

java - 调用 Spring 服务(导入 java.net.URL.* 包) POST 其调用但在响应时收到 java.io.FileNotFoundException

spring-mvc - Spring 3.1 基于 Java 的配置如何工作

java - 为什么从请求中获取第一个参数是错误的?

java - File.exists() 方法总是返回 true,即使文件不存在

css - 具有 Angular 应用程序静态内容行为的 Spring Boot MVC?

java - 使用 Spring @RestController 处理带 ZonedDateTime 参数的 HTTP GET

java - ThreadLocal 中的 UUID.randomUUID

java - 背景图像未显示在 JPanel 中