title: Unable to Get data from Spring Boot API with Postman or by typing in URL
body: <p>I am doing a project and I'm trying to Get user data by name. So far I can Post my Json data into my H2 database successfully. But that, and getting data by typing in ID# in the URL are the only things that works. So far I stopped using my intended function <code>public List&lt;User&gt; getUserByTheName(String name)</code> in <code>userService.java</code> because it simply doesn't work.</p>
  <p>I cannot Get all data nor can I get user data by name using my function <code>public List&lt;User&gt; getUserByName(@PathVariable(&quot;name&quot;) String name)</code> in <code>Controller.java</code>. Postman does not Get any user data, <code>http://localhost:8080/users</code> does not show all user data, and <code>http://localhost:8080/user/name/{user}</code> does not show any data. I only get <code>error 500</code> on screen.</p>
  <p>I'm not sure what the problem could be or what trail to follow in regards to this. Posting data works fine but Getting data does not. I can search by ID# in URL but I cannot search by name in URL.</p>
  <p><a href="https://i.stack.imgur.com/DrGWw.jpg" rel="nofollow noreferrer">My Project Folder Hierarchy</a></p>
  <p>Main.java</p>
  <pre><code>package com.geektext;
  
  import org.springframework.boot.SpringApplication;
  
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.builder.SpringApplicationBuilder;
  import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  
  
  @SpringBootApplication
  public class Main extends SpringBootServletInitializer {
      
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          System.out.println(&quot;Started ...&quot;);
          SpringApplication.run(Main.class, args);
      }
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
          return builder.sources(Main.class);
      }
  }
  </code></pre>
  <p>Controller.java</p>
  <pre><code>package com.geektext.controller;
  
  import java.util.List;
  import java.util.stream.Collectors;
  
  // Imports needed to create RESTful API, do not edit.
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.DeleteMapping;  
  import org.springframework.web.bind.annotation.GetMapping;  
  import org.springframework.web.bind.annotation.PathVariable;  
  //import org.springframework.web.bind.annotation.PostMapping;  
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.geektext.user.User;
  import com.geektext.userService.userService; 
  
  
  // RESTful Controller
  @RestController
  public class Controller {
      
      
      @Autowired
      userService userService;
      
      
      // Create a @GetMapping that retrieves all user details from the database   
      @GetMapping(&quot;/users&quot;)
      public List&lt;User&gt; getAllUsers() {
          List&lt;User&gt; list =  userService.getAllUser();
          return list;
      }
      
      // Create a @GetMapping that retrieves the detail of a specific student by id
      @GetMapping(path =&quot;/user/{id}&quot;)
      public User getUser(@PathVariable(&quot;id&quot;) int id) {
          return userService.getUserById(id);
      }
      
      // Create a @GetMapping that retrieves the detail of a specific student by name
      @GetMapping(value = &quot;/user/name/{name}&quot;)
      public List&lt;User&gt; getUserByName(@PathVariable(&quot;name&quot;) String name) {
          return userService.getAllUser().stream().filter(n -&gt; n.getUser_name().matches(name)).collect(Collectors.toList());
      }
      
      // Create a @DeleteMapping that deletes a specific student
      @DeleteMapping(path =&quot;/user/{id}&quot;)
      public void deleteUser(@PathVariable(&quot;id&quot;) int id) {
          userService.deleteData(id);
      }
      
      // Create a @PostMapping that posts the detail of a specific student
      //@PostMapping(path = &quot;/user&quot;)
      @RequestMapping(value = &quot;/user&quot;, method = {RequestMethod.POST})
      public int saveUser(@RequestBody User user) {
          //System.out.print(&quot;print me&quot;);
          userService.saveData(user);
          return user.getUser_id();   
      }
      
  }
  
  </code></pre>
  <p>userService.java</p>
  <pre><code>package com.geektext.userService;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import com.geektext.user.User;
  import com.geektext.userRepository.UserRepository;
  import com.geektext.userRepository.UserRepositoryImpl;
  
  
  @Service
  public class userService extends UserRepositoryImpl {
      
      @Autowired
      UserRepository userRepository;
      UserRepositoryImpl userRepositoryImpl;
      
      // Function to query all user data
      public List&lt;User&gt; getAllUser() {
          List&lt;User&gt; users = new ArrayList&lt;&gt;();
          userRepository.findAll().forEach(user -&gt; users.add(user));
          return users;
      }
      
      
      // Function to query one specific user
      public User getUserById(int id) {
          return userRepository.findById(id).orElseGet(null);
      }
      
      
      // Function to save or update a user
      public void saveData(User user) {
          userRepository.save(user);
      }
      
      
      // Function to delete a specific user by id
      public void deleteData(int id) {
          userRepository.deleteById(id);
      }
  
  
      //@Override
      public List&lt;User&gt; getUserByTheName(String name) {       
          return userRepositoryImpl.findAllUsers(name);
      }
  
  }
  </code></pre>
  <p>UserRepository.java</p>
  <pre><code>package com.geektext.userRepository;
  
  import java.util.List;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.repository.CrudRepository;
  
  
  import com.geektext.user.User;
  
  public interface UserRepository extends JpaRepository&lt;User, Integer&gt; {
      public List&lt;User&gt; findAllUsers(String userName);
      public List&lt;User&gt; getUserByName(Iterable&lt;User&gt; iterable, String userName);
  }
  </code></pre>
  <p>UserRepositoryCustom.java</p>
  <pre><code>package com.geektext.userRepository;
  
  import java.util.List;
  
  import com.geektext.user.User;
  
  public interface UserRepositoryCustom {
      public List&lt;User&gt; findAllUsers(String userName);
      public List&lt;User&gt; getUserByName(Iterable&lt;User&gt; iterable, String userName);
  
  
  }
  </code></pre>
  <p>UserRepositoryImpl.java</p>
  <pre><code>package com.geektext.userRepository;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import com.geektext.user.User;
  
  public class UserRepositoryImpl implements UserRepositoryCustom {
      UserRepository userRepository;
      UserRepositoryCustom userRepoCust;
      User user;
      
      public List&lt;User&gt; findAllUsers(String userName) {
          Iterable&lt;User&gt; findAllIterable = userRepository.findAll();
          return getUserByName(findAllIterable, userName);
      }
  
      public List&lt;User&gt; getUserByName(Iterable&lt;User&gt; iterable, String userName) {
          List&lt;User&gt; listOfStudents = new ArrayList&lt;&gt;();
          for (User user : iterable) {
              if (user.getUser_name().equalsIgnoreCase(userName)) {
                  System.out.print(user.getUser_name());
                  listOfStudents.add(user);
              }   
          }
          return listOfStudents;
      }
  }
  </code></pre>
  <p>User.java</p>
  <pre><code>package com.geektext.user;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  @Entity  
  @Table
  public class User {
      //mark id as primary key  
          @Id  
          //defining user_id as column name  
          @Column  
          private int user_id;
          //defining user_name as column name  
          @Column  
          private String user_name;
          //defining user_password as column name  
          @Column  
          private String user_password;
          //defining user_email_address as column name   
          @Column  
          private String user_email_address;
          //defining user_home_address as column name   
          @Column  
          private String user_home_address;
          
          
          public String getUser_email_address() {
              return user_email_address;
          }
          public void setUser_email_address(String user_email_address) {
              this.user_email_address = user_email_address;
          }
          public String getUser_home_address() {
              return user_home_address;
          }
          public void setUser_home_address(String user_home_address) {
              this.user_home_address = user_home_address;
          }
          public int getUser_id() {
              return user_id;
          }
          public void setUser_id(int user_id) {
              this.user_id = user_id;
          }
          public String getUser_name() {
              return user_name;
          }
          public void setUser_name(String user_name) {
              this.user_name = user_name;
          }
          public String getUser_password() {
              return user_password;
          }
          public void setUser_password(String user_password) {
              this.user_password = user_password;
          }
          
  }
  </code></pre>
  <p>pom.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.6.3&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;demo&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
      &lt;properties&gt;
          &lt;java.version&gt;11&lt;/java.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>