title: java.lang.NullPointerException: null when try to inject spring container in controller
body: <p>hello guys i have  a noob question .i try to build a simple login page.
  i do have @resource the jparepository at my controller .but log said nullpointexception.
  i have try main start with  getbean() to reach user in my sql ,it can be done. but why
  cant i reach it in controller. sorry its my first time ask so that forgive my formatted form.</p>
  <pre><code>@Controller
  public class indexController {
      
      @Resource
      private jpaRepository2 jpa2;
      
      @GetMapping(&quot;/index&quot;)
      public  String index()
      {
          return &quot;index&quot;;
      }
  
      @RequestMapping(&quot;/login&quot;)
      public  String login(@RequestParam(&quot;username&quot;) String username,@RequestParam(&quot;password&quot;) String password)
      {
          user user2 = jpa2.findByName(username);
          if(password == user2.getPassword())
          {
              return &quot;index&quot;;
          }else
          {
              return &quot;logged&quot;;
          }
      }
  
  **@Repository
  public interface jpaRepository2 extends JpaRepository&lt;user,Integer&gt;{
  
      @Query(value=&quot;select * from user where username = ?&quot;,nativeQuery=true)
       user  findByName( String name);
      
  }**
  
  entity
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name=&quot;user&quot;)
  public class user {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name=&quot;id&quot;)
      private Integer id;
      @Column(name=&quot;username&quot;)
      private String username;
      @Column(name=&quot;password&quot;)
      private String password;
      public String getUsername() {
          return username;
      }
      public void setUsername(String username) {
          this.username = username;
      }
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
      @Override
      public String toString() {
          return &quot;user [username=&quot; + username + &quot;, password=&quot; + password + &quot;]&quot;;
      }
      
  }
  
  the following is log:......
  
  java.lang.NullPointerException: null
  at com.mickey.controller.indexController.login(indexController.java:37) ~[classes/:na]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_281]
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_281]
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_281]
  </code></pre>