Java 如何在Spring中从文件连接JSON数据?

Java 如何在Spring中从文件连接JSON数据?,java,json,spring,Java,Json,Spring,我有一个简单的Spring应用程序。在那个应用程序中,我有@Repository,它应该提供对JSON文件和我的数据的访问 @Repository("jsonStorageUserRepository") public class JsonUserRepository implements UserRepository { @Value("${users}") private List<User> users; @Override public U

我有一个简单的Spring应用程序。在那个应用程序中,我有
@Repository
,它应该提供对
JSON
文件和我的数据的访问

@Repository("jsonStorageUserRepository")
public class JsonUserRepository implements UserRepository {

    @Value("${users}")
    private List<User> users;

    @Override
    public User getByCursor(Cursor cursor) {
        return users.get(cursor.getId);
    }
}
和我的
DTO
课程-

public class User implements Serializable {
    private boolean registered;
    private String name;

    public User(String name, boolean redistricted) {
        this.name = name;
        registered = redistricted;
    }
    // setters and getters were omitted
}
现在我有一个例外:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonStorageUserRepository': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List com.springapp.mvc.repository.json.JsonUserRepository.users; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'users' in string value "${users}"
它与这一行有关-

@Value("${users}")
private List<User> users;
@Value(“${users}”)
私人名单用户;

是否可以从
JSON
连接转换后的实体列表?

读取JSON格式的属性文件将不起作用。您需要编写自定义属性编辑器。看看那篇文章:


spring找不到您的属性文件:

Could not resolve placeholder 'users' in string value "${users}"


可能PropertyPlaceHolderConfigure配置错误。

@Alex请显示您的context.XML。因此,我们可以看到问题所在。在我的上下文中,我没有任何
自定义编辑器或配置程序
。我正在尝试实现它…您希望
${users}
从哪里来?为什么?在我的
属性
项目文件夹中,我有一个文件
users.json
。我想从那里读取属性。我把我的数据存储在这个文件中。为什么你认为你给我们看的东西可以做到这一点?不,我的代码不起作用。问题是如何读取json格式的属性,并将它们放入某个组件bean中。问题是
如何强制Spring从*.json文件读取属性?
Could not resolve placeholder 'users' in string value "${users}"
@Value("${users}")