Http 404 spring mvc [duplicate] - spring

This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 5 years ago.
i am not able to figure out how to solve 404 error in running an spring mvc application .
can some one please guide me how to avoid 404 error in general for spring mvc application without using annotation configuration rather xml configuaration .
Please also let me know of working war file or zip which i can import in eclipse for spring mvc directly and learn about the components .
Thanks
Prakaash

HTTP 404 mean that the requested resource (url) is not found.
In most cases either:
Your Application is not really started
Your Application is mapped to an complete different url than you expected
There is no handler for the requested url in the application
So in general: 404 is not a error by itself, in the most cases it is a bug in your application or in your understanding of how it works.
But you will not get an better answer, as long as you do not post more details about your application, as well as the URL you try to invoke.

Related

I just started to run spring boot application and the browser is showing this error

Please explain me what is wrong here, why am I getting this type of error?
error message is : Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:
I am new to asking questions in stack overflow , please suggest me on how to structure this question properly
[1]: https://i.stack.imgur.com/wXxnS.png
You forgot to add this annotation, please add this to main class.
#EnableSwagger2

Custom error page routing struts 2 + spring boot

I am trying to run a struts 2 application in spring boot provided embedded tomcat, I have managed to do so following the link https://jgalacambra.wordpress.com/2016/06/13/spring-boot-and-struts-2/. The application is working, however I am not able to get through the custom page error routing based on http error code which was configured earlier in web.xml. I have tried below solutions so far and none of them seems to work as I keep getting default tomcat error page for 404.
Things I have tried so far:
1.Disabled white label error page using.
"server.error.whitelabel.enabled=false"
2.created public/error folder in src/main/resouces and placed all html error code related html files there.
3.Also tried creating templates folder under src/main/resources and placed http error code files there.
4.I have also configured my filterregistration bean with below setting.
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
Can someone please help what needs to be done for the error routing to work???

Spring 4 MVC Hibernate Resource not found

Was recently following this tutorial : https://examples.javacodegeeks.com/enterprise-java/spring/mvc/spring-mvc-hibernate-tutorial/ , I have followed everything mentioned there but when I go access my app it just shows a 404 with message "The requested resource is not available."
I have already made sure my app compiles and no error were found, I wonder what could be wrong?
also where should i look at for integrating spring 4 with hibernate?
thanks

Wildfly Undertow HTTP Response 200 but no content

I am developing a simple web service using Eclipse Java EE IDE for Web Developers : Version: Kepler Service Release 2 Build id: 20140224-0627 and Wildfly-8.2.0.Final. I chose wildfly-javaee7-webapp-blank-archetype using Maven and started development. Firstly, there was no problem, I could add some simple jsp pages and also a simple html page with some images and javascript inclusion then I could deployed, launched and accessed those pages by browser. But all of a sudden, Wildfly (I guess Undertow maybe?) started to response with HTTP response 200 with no content... I really don't get what is going on. I also did rollback my sources to the very early simple pages only. But still the symptoms are the same. Also I have tried to use newer version of Wildfly-9.0.1.Final and deployed manually but I haven't seen any difference.
ex1) this is ok. (Of course browsers take care of this...)
ex2) this kind of contents won't be loaded and sent back as content 0...
I doubted local path issue but I haven't changed anything and it was loaded earlier.
It would be really appreciated if somebody could give me a solution.
Finally I have solved this problem. I have found a problem on a servlet I have added at last. Actually I was trying to migrate my web service running on glassfish and did migrate files one by one. I specified a URL to be handled by the servlet in Web.xml when it run on glassfish. But somehow, it's not working on Wildfly which means all URL request are unexpectedly handled by the servlet... Since I have no idea to specify url to be handled by the specific servlet in Web.xml for Wildfly, I decided to filter request URL in the servlet code. So it is working now. Thank you guys trying to help me...

How can I populate dynamic information on a custom Tomcat 404 page?

I'm putting together a web app using Tomcat + Spring, and I'd like to have custom 404 pages which contain dynamic content, not just a static html file. For example, if I were working on a blog site, I might want to show a list of the 5 most recent posts on the 404 page to direct the user to actual content.
Additionally, is there a way I can leverage the error information when generating the error page? For example, if the error involved an exception happening in my app, as opposed to a bad url, can I display the stack trace?
Are you creating the project from scratch? Are you able to use Spring-Boot? Spring Boot provides a lot of nice error handling functionality out of the box that can be easily modified.
Either way, if you just want to use standard error page mapping in the web.xml, or example:
<error-page>
<error-code>404</error-code>
<location>/error/404</location>
</error-page>
When your application returns a 404 status code, the request will be intercepted and forwarded internally to the endpoint /error/404 - which can just be any endpoint in your spring app, so can do any dynamic stuff that you would in a normal controller.
To do it programatically, without Spring Boot, you could create a Filter class that wraps all requests and just catches exceptions and checks for non 2XX response codes and forwards/handles appropriately - this is basically the solution that the Spring Boot guys implemented (see the ErrorPageFilter class).
To access info about the exception, that can be accessed from the request - see here for similar answer: https://stackoverflow.com/a/1034667/258813

Resources