title: Java Spring Web application Nullpointer
body: <p>I'm currently trying to create my first Java web application using Spring boot and Spring data.
  I wrote a Controller already and now trying to create Datas in an inmemory-database. </p>
  
  <p>I am getting a nullpointer exception when I try to create a new User. Allthough the user has every value set. </p>
  
  <p>POJO:</p>
  
  <pre><code>package db;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  @Entity
  public class User {
  @Id
  @GeneratedValue(strategy= GenerationType.AUTO)
  private Long id;
  
  private String userName;
  
  private String email;
  
  private String password;
  
  protected User() {}
  
  public Long getId() {
      return id;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getUserName() {
      return userName;
  }
  
  public void setUserName(String userName) {
      this.userName = userName;
  }
  
  public String getEmail() {
      return email;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>DAO:</p>
  
  <pre><code>package db;
  
  import java.util.List;
  
  import org.springframework.data.repository.CrudRepository;
  import org.springframework.stereotype.Repository;
  
  @Repository
  public interface UserRepository extends CrudRepository&lt;User, Long&gt; {
  
      List&lt;User&gt; findByUserName(String userName);
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>package db;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  
  @Service
  public class UserService {
  
      @Autowired
      UserRepository repository;
  
      private static final Logger log = LoggerFactory.getLogger(Application.class);
  
      public User start() {
          User user = new User();
          user.setEmail("alovela@uk.com");
          user.setUserName("Ada");
          user.setPassword("Password");
  
          repository.save(user);
  
          return user;
      }
  }
  </code></pre>
  
  <p>Error when calling UserService.start(); in my main:</p>
  
  <pre><code>2017-07-11 20:31:10.027 ERROR 7604 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  </code></pre>
  
  <p>java.lang.NullPointerException: null</p>