【问题标题】:ArangoRepository causing NullPointerExceptionArangoRepository 导致 NullPointerException
【发布时间】:2020-03-05 15:45:49
【问题描述】:

在尝试针对 ArangoDB 构建 Spring Boot 微服务时,我在使用存储库对象时收到 NullPointerException。这是涉及的代码:

加载所有存储库的配置类:

@EnableArangoRepositories(basePackages= {"com.parapentex"})
public class ArangoDBTestConfig extends AbstractArangoConfiguration{

存储库类:

package com.parapentex.repository;

import com.arangodb.springframework.repository.ArangoRepository;
import com.parapentex.entity.User;

public interface UserRepository extends ArangoRepository<User>{

}

还有服务类:

public class UserService {

    @Autowired 
    private UserRepository repository;

    /**
     * Create an user
     * 
     * @param user
     * @return
     */
    public User save(String user) {
        User newUser = new User();
        JSONObject userJSON = new JSONObject(user);
        try {
            newUser.setName(userJSON.getString("name"));
            newUser.setAge(userJSON.getInt("age"));
        } catch (Exception e) {
            e.printStackTrace();
        }
System.out.println(repository);     
        return repository.save(newUser);
    }

我在哪里得到 NullPointerException(存储库未实例化)。

有什么想法吗?

java.lang.NullPointerException: null
    at com.parapentex.unvist.service.UserService.save(UserService.java:32) ~[classes/:na]
    at com.parapentex.unvist.controller.UserController.create(UserController.java:30) ~[classes/:na]

谢谢!

【问题讨论】:

  • 如何实例化UserService
  • 你能发布所有类的包,尤其是服务和配置。
  • 在控制器中...但是那里出错了!非常感谢!

标签: java spring arangodb


【解决方案1】:

只是服务类中的错误配置!固定。

【讨论】:

    猜你喜欢
    • 2016-03-07
    • 2017-05-16
    • 2014-06-09
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多