This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

404 not found - Spring boot - Rest api

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've created a simple rest api. when i tried to hit the resource , i get 404 not found error. i googled but couldn't find any help. can somebody guide me?

P.S: if you need anymore information , let me know.






Error:


2020-10-04 13:50:53.129 DEBUG 18704 --- [nio-8080-exec-2] o.a.coyote.http11.Http11InputBuffer      : Received [GET /catalog/1 HTTP/1.1
User-Agent: PostmanRuntime/7.26.5
Accept: */*
Cache-Control: no-cache
Postman-Token: 2d855b91-4ee7-408f-99f0-5d89780e7902
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

]
2020-10-04 13:50:53.129 DEBUG 18704 --- [nio-8080-exec-1] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header

java.io.EOFException: null
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1231) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1141) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:791) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:355) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:261) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at java.base/java.lang.Thread.run(Thread.java:835) ~[na:na]

 
Saloon Keeper
Posts: 13427
302
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us where you have your application configured to use Spring as the front controller. Are you using Spring boot? Do you have a web.xml?
 
ssiva raman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Stephan,

thank you for the reply.

yes , I'm using spring boot.

Please find the pom.xml.

 
Stephan van Hulst
Saloon Keeper
Posts: 13427
302
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your application contain a context.xml file?
 
ssiva raman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Does your application contain a context.xml file?



No, Stephan.
 
Stephan van Hulst
Saloon Keeper
Posts: 13427
302
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a main class annotated with @SpringBootApplication? What package is it in? What package is your controller in?
 
ssiva raman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Do you have a main class annotated with @SpringBootApplication? What package is it in? What package is your controller in?



They are in different package. is it a problem?



 
Stephan van Hulst
Saloon Keeper
Posts: 13427
302
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I think this is causing your issue.

By default, component scanning occurs in the package of your main application class, or sub-packages. com.example.Controller is not a sub-package of com.example.demo.

You could specify the name of the package to scan for components like this:
It's better however, to instead use a more sensible package hierarchy. For instance, if com.example.demo is the base package of your project, put the main application class in com.example.demo.spring and put your controllers in com.example.demo.spring.controller. This will enable component scanning for the com.example.demo.spring package (and also its sub-packages like com.example.demo.spring.controller) while skipping it for packages that don't need it. That way you could put your business model in com.example.demo, and it won't take up any resources being scanned needlessly.

  • src/main/java/
    • com/example/demo/
      • Movie.java
      • spring/
        • MovieCatalogSvcsApplication.java
        • controller/
          • MovieCatalogController.java

Please use proper Java naming conventions. Package name elements should not be capitalized, and write out names (e.g. Controller instead of Ctrl).
 
ssiva raman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Yes, I think this is causing your issue.



you're right, Stephan. thank you for spotting.

By default, component scanning occurs in the package of your main application class, or sub-packages. com.example.Controller is not a sub-package of com.example.demo.



The below change solved the problem. However , i'll rearrange the project hierarchy as you suggested.


You could specify the name of the package to scan for components like this:
It's better however, to instead use a more sensible package hierarchy. For instance, if com.example.demo is the base package of your project, put the main application class in com.example.demo.spring and put your controllers in com.example.demo.spring.controller. This will enable component scanning for the com.example.demo.spring package (and also its sub-packages like com.example.demo.spring.controller) while skipping it for packages that don't need it. That way you could put your business model in com.example.demo, and it won't take up any resources being scanned needlessly.

  • src/main/java/
    • com/example/demo/
      • Movie.java
      • spring/
        • MovieCatalogSvcsApplication.java
        • controller/
          • MovieCatalogController.java

Please use proper Java naming conventions. Package name elements should not be capitalized, and write out names (e.g. Controller instead of Ctrl).



sure, thank you for the suggestions.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic