title: HTTP 405 Request method 'PUT' not supported
body: <p>Im trying to do a crud with spring boot and I got this error of update in postman.</p>
  <p>URL:http://localhost:8085/api/v1/student?18&amp;name=student1&amp;email=student@gmail.com</p>
  <p>type of error:
  <em>&quot;timestamp&quot;: &quot;2021-05-15T04:25:55.895+00:00&quot;,
  &quot;status&quot;: 405,
  &quot;error&quot;: &quot;Method Not Allowed&quot;,
  &quot;message&quot;: &quot;Request method 'PUT' not supported&quot;,
  &quot;path&quot;: &quot;/api/v1/student&quot;</em></p>
  <p>this is my <em><strong>studentService.java</strong></em></p>
  <pre><code>
  import java.util.List;
  import java.util.Objects;
  import java.util.Optional;
  
  import javax.transaction.Transactional;
  
  import java.lang.IllegalStateException;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  @Service
  public class StudentService {
      private final StudentRepository studentRepository;
  
      @Autowired
      public StudentService(StudentRepository studentRepository) {
          this.studentRepository = studentRepository;
      }
  
      public List&lt;Student&gt; GetStudents() {
  
          return this.studentRepository.findAll();
  
      }
  
      public void addNewStudent(Student student) {
          Optional&lt;Student&gt; studentOptional = studentRepository.findStudentByEmail(student.getEmail());
          if (studentOptional.isPresent()) {
              throw new IllegalStateException(&quot;email taken&quot;);
          }
          studentRepository.save(student);
      }
  
      public void deleteStudentByID(Long studentID) {
          boolean exists = studentRepository.existsById(studentID);
  
          if (!exists) {
              throw new IllegalStateException(&quot;student with &quot; + studentID + &quot; does not exist!&quot;);
  
          }
          studentRepository.deleteById(studentID);
      }
  
      @Transactional
      public void updateStudentByID(Long studentID, String name, String email)
  
      {
          Student student = studentRepository.findById(studentID)
                  .orElseThrow(() -&gt; new IllegalStateException(&quot;student with id&quot; + studentID + &quot;does not exist&quot;));
          if (name != null &amp;&amp; name.length() &gt; 0 &amp;&amp; !Objects.equals(student.getName(), name)) {
              student.setName(name);
          }
          if (email != null &amp;&amp; email.length() &gt; 0 &amp;&amp; !Objects.equals(student.getEmail(), email)) {
              Optional&lt;Student&gt; studentOptional = studentRepository.findStudentByEmail(student.getEmail());
              if (studentOptional.isPresent()) {
                  throw new IllegalStateException(&quot;email taken&quot;);
              }
              student.setEmail(email);
          }
  
      }
  
  }
  </code></pre>
  <p><em><strong>My controller</strong></em></p>
  <pre><code>
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  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.PutMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  @RequestMapping(path = &quot;api/v1/student&quot;)
  public class StudentController {
      private final StudentService studentService;
  
      @Autowired
      public StudentController(StudentService studentService) {
          this.studentService = studentService;
      }
  
      @GetMapping
      public List&lt;Student&gt; GetStudents() {
  
          return studentService.GetStudents();
  
      }
  
      @PostMapping
      public void registerNewStudent(@RequestBody Student student) {
          studentService.addNewStudent(student);
      }
  
      @DeleteMapping(path = &quot;{studentId}&quot;)
      public void deleteStudent(@PathVariable(&quot;studentId&quot;) Long studentID) {
          studentService.deleteStudentByID(studentID);
      }
  
      @PutMapping(path = &quot;{studentId}&quot;)
      public void updateStudent(@PathVariable(&quot;studentId&quot;) Long studentID, @RequestParam(required = false) String name,
              @RequestParam(required = false) String email) {
          studentService.updateStudentByID(studentID, name, email);
      }
  }
  </code></pre>
  <p>this is <em><strong>studentConfig.java</strong></em></p>
  <pre><code>
  import java.util.List;
  
  import org.springframework.boot.CommandLineRunner;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  public class StudentConfig {
  
      @Bean
      CommandLineRunner commandLineRunner(StudentRepository repository) {
          return args -&gt; {
              Student st1= new Student(&quot;student11&quot;, &quot;email&quot;, &quot;17&quot;, 21);
              Student st2= new Student(&quot;student22&quot;, &quot;email&quot;, &quot;17&quot;, 22);
  
              repository.saveAll(List.of(st1, st2));
  
          };
      }
  }
  </code></pre>
  <p>this is my <em><strong>Repository</strong></em></p>
  <pre><code>
  import java.util.Optional;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  
  public interface StudentRepository extends JpaRepository&lt;Student, Long&gt; {
  Optional &lt;Student&gt; findStudentByEmail(String email);
  }
  </code></pre>