title: 404-not-found-while-running-spring-boot-rest-api
body: <p>While running springboot restservice application got 404 error.  I am using spring boot, jersey rest. I have tried GET requests <em><code>http://localhost:8080/dunames</code></em> but not able to resolve. Please help.  </p>
  
  <p><strong>Model Class:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "du")
  public class duname {
  
  
      private String duname;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id; 
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public duname()
      {
  
      }
  
      public duname(String duname, int id)
      {
      this.duname=duname; 
      this.id=id;
      }
  
  
      public String getDuname() {
          return duname;
      }
  
      public void setDuname(String duname) {
          this.duname = duname;
      }
  }
  </code></pre>
  
  <p><strong>Service Class:</strong> </p>
  
  <pre><code>public class duservice {
  
      @Autowired
      private durepo durepository;
  
      public List&lt;duname&gt; getAlldu()
      {
          List&lt;duname&gt; dunames=new ArrayList&lt;duname&gt;();
          durepository.findAll()
          .forEach(dunames::add);
          return dunames;
      }
  
      public void addDu(duname dunames)
      {
          durepository.save(dunames);
      }
  
      public duname getDu(int id)
      {
          return durepository.findOne(id);
      }
  
      public void deleteDu(int id)
      {
          durepository.delete(id);
      }
  
      public void updateDu(int id, duname dunames)
      {
          durepository.save(dunames);
      }
  }
  </code></pre>
  
  <p><strong>Controller class:</strong></p>
  
  <pre><code>    @RestController
  public class ducontroller {
  
  
      @Autowired
      private duservice duService;
  
      private final Logger log=(java.util.logging.Logger) LoggerFactory.getLogger(ducontroller.class);
  
  
      @RequestMapping("/dunames")
      public List&lt;duname&gt; getAlldu()
      {
            log.info("Starting");
      return duService.getAlldu();
      }
  
      @RequestMapping("/duname/{id}")
      public duname getdu(@PathVariable int id)
      {
          return duService.getDu(id);
      }
  
      @RequestMapping(method=RequestMethod.POST,value="/dunames")
      public void addDuname(@RequestBody duname dunames)
      {
          duService.addDu(dunames);
      }
  </code></pre>
  
  <p><strong>Repository:</strong> </p>
  
  <pre><code>public interface durepo extends CrudRepository&lt;duname,Integer&gt; {
  
  
  }
  </code></pre>
  
  <p><strong>Main Class:</strong></p>
  
  <pre><code> @SpringBootApplication
  public class DuaddApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(DuaddApplication.class, args);
      }
  }
  </code></pre>
  
  <p><strong>Pom File:</strong></p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.du&lt;/groupId&gt;
      &lt;artifactId&gt;duadd&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;duadd&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&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;1.5.8.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&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-jersey&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.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&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;/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;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>Application Properties:</strong></p>
  
  <pre><code>spring.datasource.url=jdbc:postgresql://localhost:2280/todo
  spring.datasource.username=test
  spring.datasource.password=test
  spring.jpa.generate-ddl=true
  server.port=8080 
  </code></pre>
  
  <p>Some console output:</p>
  
  <pre><code>2017-10-26 11:06:08.952  INFO 4552 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
  2017-10-26 11:06:08.975  INFO 4552 --- [           main] com.soprasteria.du.DuaddApplication      : Started DuaddApplication in 7.096 seconds (JVM running for 7.633)
  2017-10-26 11:06:32.779  INFO 4552 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
  2017-10-26 11:06:32.779  INFO 4552 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
  2017-10-26 11:06:32.800  INFO 4552 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 21 ms
  </code></pre>