title: Spring Boot REST API Generates 404 Not Found
body: <p>I am trying to execute Spring boot application which is connected to MySQL (phpmyadmin) database.The issue is when I try to get, delete or post data, it generates this message.</p>
  
  <pre><code>{
    "timestamp": "2018-07-02T06:36:37.000+0000",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/api/users"
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>public class App extends SpringBootServletInitializer {
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(App.class);
      }
      public static void main( String[] args )
      {
          System.out.println( "Hello World!" );
          SpringApplication.run(App.class, args);
      }
  }
  </code></pre>
  
  <p>Dependencies:</p>
  
  <pre><code>&lt;dependencies&gt;
        &lt;dependency&gt;
          &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
          &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
          &lt;/dependency&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;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&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;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf-extras-springsecurity4&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.nulab-inc&lt;/groupId&gt;
              &lt;artifactId&gt;zxcvbn&lt;/artifactId&gt;
              &lt;version&gt;1.2.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sourceforge.nekohtml&lt;/groupId&gt;
              &lt;artifactId&gt;nekohtml&lt;/artifactId&gt;
              &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-mail&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;version&gt;1.4.191&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>Application.properties</p>
  
  <pre><code>    spring.datasource.url = jdbc:mysql://localhost:3306/demo_db?useSSL=false
      spring.datasource.username=root
      spring.datasource.password=root
      spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
      spring.jpa.hibernate.ddl-auto=create
      spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
      spring.datasource.driverClassName=com.mysql.jdbc.Driver
      spring.jpa.generate-ddl=true
      spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
  </code></pre>
  
  <p>UserController:</p>
  
  <pre><code>@RestController
  @RequestMapping("/api")
  public class UserController {
  
      @Autowired
      UserRepository userRepoObject;
  
      @GetMapping("/users")
      public List&lt;User&gt; getAllUsers(){
          return userRepoObject.findAll();
      }
  
      @PostMapping("/users")
      public User createUser(@Valid @RequestBody User userObj) {
          return userRepoObject.save(userObj);
      }
  
      @GetMapping("/users/{id}")
      public User getUser(@PathVariable(value = "id") Long userId) {
          return userRepoObject.findById(userId)
                  .orElseThrow(() -&gt; new ResourceNotFoundException("User", "id", userId));
      }
  
      @DeleteMapping("users/{id}")
      public ResponseEntity&lt;?&gt; deleteUser(@PathVariable(value="id") Long userId){
          User user = userRepoObject.findById(userId).orElseThrow(() -&gt; new ResourceNotFoundException("User","id",userId));
          userRepoObject.delete(user);
          return ResponseEntity.ok().build();
      }
  
  }
  </code></pre>
  
  <p>Apart from that, I have User, UserController, and UserRepository class in my app. demo_db database and user table is already been created in phpmyadmin. </p>
  
  <p>Please help me out with the issue. Many thanks in advance.</p>
  
  <p>For more information attaching screenshots of errors. </p>
  
  <p><a href="https://i.stack.imgur.com/SE6dY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SE6dY.png" alt="enter image description here"></a></p>