When trying to build a Spring Boot microservice against ArangoDB, I'm getting a NullPointerException when using the repository object. This is the code involved:
Config class that loads all repositories:
@EnableArangoRepositories(basePackages= {"com.parapentex"})
public class ArangoDBTestConfig extends AbstractArangoConfiguration{
Repository class:
package com.parapentex.repository;
import com.arangodb.springframework.repository.ArangoRepository;
import com.parapentex.entity.User;
public interface UserRepository extends ArangoRepository<User>{
}
And the service class:
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);
}
where I'm getting the NullPointerException (Repository not intantiated).
Any idea?
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]
Thanks!