• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Http 404 after requesting to endpoint

 
Ranch Hand
Posts: 123
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to write Spring application in Spring 3.0.x (yes I want that version). Made a really simple method that returns String.



After calling http://localhost:8080/sayHello I'm getting 404 don't know why.



I'm using Tomcat 8.5.60.

My pom.xml



web.xml



DispartcherServlet-context.xml



Could you tell me what I'm doing wrong to make this Controller work?

 
Marshal
Posts: 3457
493
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat can support multiple web applications.  Unless you have done some special configuration to make your application the root application, the URLs to your resources will need to include the application's name in the path.

For example: http://localhost:8080/myapp/sayHello
 
must Janik
Ranch Hand
Posts: 123
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem was that webapp director was not under src/main.
In logs right now I get:



so I moved forward, but still getting 404 on stara/sayHello or /sayHello

I also added
<dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-webmvc</artifactId>
           <version>3.0.7.RELEASE</version>
       </dependency>
dependency to pom.xml
 
Saloon Keeper
Posts: 23411
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just out of curiosity, why use such an ancient version of Spring?

More practically, are you using Spring Boot or building a standard JEE WAR?

And if you're building a standard JEE WAR, how are you deploying it into Tomcat?
 
must Janik
Ranch Hand
Posts: 123
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because I'm comparing app written in Spring Boot and in Spring 3 + jdk 7 for my engineering thesis.

I'm building war. I'm deploying it like this https://bykowski.pl/wdrazanie-aplikacji-spring-na-tomcat/ (it is on polish, but you can conclude from screens how I do it.
 
Tim Holloway
Saloon Keeper
Posts: 23411
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately, that means nothing to me. I don't recognize the GUI, but none of the screenshots appear to indicate where the WAR was copied from into Tomcat or what its structure was.

The Tomcat Manager webapp would show the context name(s) for deployed WARs, but none of what you snapshotted does.
 
must Janik
Ranch Hand
Posts: 123
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I added TomcatServer in Configurations of Intellij and before lunch I have appname:war exploded artifact. That's how I'm deploying war on tomcat.
Full logs after running app (deploying in tomcat)


 
Tim Holloway
Saloon Keeper
Posts: 23411
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the reasons why we discourage over-reliance on IDEs is because they tend to keep you from knowing the details. I'd probably also object to the use of anything that obscures the purity of my objects of study when doing an academic exercise too, but that's another matter.

What actually matters is that I'm not seeing one of the log messages that tells me for certain about the deployment. But I think you may find your webapp at either of these two URLs:

http://localhost:8080/stara/sayHello
http://localhost:8080/stara:war/sayHello

Although the second URL is probably not valid URL syntax.
 
must Janik
Ranch Hand
Posts: 123
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
None of them works which is werid as...
 
Tim Holloway
Saloon Keeper
Posts: 23411
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try http://localhost:8080/manager

It's only weird because you're using crutches. IDEs are wonderful - once you understand what they're doing. But no Intelligent Design Environment can replace the designer's intelligence.
 
Ron McLeod
Marshal
Posts: 3457
493
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This line in the log doesn't look right:I would have expected it to be deployed directly under the webapps directory.  It there some place (in the IDE?) where you defined the web application deployment directory to be webapps\manager?

Edit:
Maybe that is the name of the exploded directory, in which case you could try: http://localhost:8080/manager/sayHello
 
Ron McLeod
Marshal
Posts: 3457
493
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anywhere in the IDE's configuration that you override the default deployment application context?
 
must Janik
Ranch Hand
Posts: 123
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
God.... You were right Tim.
I logged into manager and I get:
stara_war_exploded as a path so I went into: stara_war_exploded/sayHello and it works...

Couple of hours wasted just for this..
Thanks a lot guys for help!
 
Marshal
Posts: 26463
81
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

must Janik wrote:Couple of hours wasted just for this..



That's life in the computer business! So, onward to the next roadblock.
 
Tim Holloway
Saloon Keeper
Posts: 23411
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:I would have expected it to be deployed directly under the webapps directory.



Well, here's the thing. JEE webapps aren't "deployed under" a directory. They're deployed under a webapp context, which is a construct internal to the webapp server (Tomcat) and associated with a URL Context Path. Which is visible via the Tomcat Manager webapp as well as via its several ReST services and APIs. The webapp obviously being the easiest one for the casual user to work with.

The basic way to deploy a webapp is to copy a WAR file or directory under TOMCAT_HOME/webapps. But all that really means is that Tomcat will periodically scan TOMCAT_HOME/webapps (or another directory, if you change the server.xml configuration) and deploy any new/changed WARs under a context path that matches the name of the WAR. Which is why I wanted to know the name and location of the "missing" webapp's WAR.

An IDE could just as easily deploy straight from a project's build directory without copying anything if it injected a Tomcat Context element that pointed to that directory. And in fact, that's my usual setup, although I manually configure Tomcat to do that, since I don't like the stock Tomcat plugin for JEE.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic