title: Spring Boot MongoRepository Null Pointer Exception
body: <p>I'm a little new to spring and I've been running into a Null Pointer Exception.
  I believe the <code>@Autowired</code> is not working on my MongoRepository.
  For some reason when I tried some examples it was working. (The commented out code in the run function worked)</p>
  
  <p>This is the error I get:</p>
  
  <blockquote>
    <p>2016-05-20 02:31:20.877 ERROR 6272 --- [nio-8080-exec-2]
    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</p>
    
    <p>java.lang.NullPointerException: null  at
    com.applesauce.service.CustomerService.addCustomer(CustomerService.java:24)
    ~[classes/:na]</p>
  </blockquote>
  
  <p>Can you guys take a look and direct me?
  Also, please let me know if i'm doing something wrong for best practices.
  If you need anymore information, please ask!</p>
  
  <p>com.applesauce.controller</p>
  
  <pre><code>@RestController 
  @RequestMapping("/customer")
  public class CustomerController {
  
  private CustomerService customerService = new CustomerService();
  
  @RequestMapping(value = "/addcustomer", method = RequestMethod.GET)
  public Customer addCustomer(@RequestParam("firstName") String fName,
                           @RequestParam("lastName") String lName,
                           @RequestParam("email") String email,
                           @RequestParam("phoneNumber") String phoneNumber,
                           @RequestParam("source") String source){
      return customerService.addCustomer(new Customer(fName,lName,email,phoneNumber,source));
  }
  }
  </code></pre>
  
  <p>com.applesauce.repository</p>
  
  <pre><code>@Repository
  public interface CustomerRepository extends MongoRepository&lt;Customer, String&gt; {
  
  public Customer findByFirstName(String firstName);
  public List&lt;Customer&gt; findByLastName(String lastName);
  }
  </code></pre>
  
  <p>com.applesauce.service</p>
  
  <pre><code>@EnableMongoRepositories(basePackages = "com.applesauce.repository")
  public class CustomerService {
  
  @Autowired
  private CustomerRepository repository;
  
  public Customer addCustomer(Customer customer){
  
      repository.save(customer);
  
      return customer;
  }
  }
  </code></pre>