Unable to run Spring REST application using Tomcat - java

I have spent the weekend trying to run some simple Spring REST applications. Lots of examples on the net. However, whenever I got to running these, my application would always give me a 404 - Resource not found exception. To ensure I was doing everything right, I even restarted the applications from scratch a few times.
If I go to the project folder and run mvn tomcat7:run the project works as expected. However, when adding the project to my Tomcat7 server inside Eclipse and running it there, I always get a 404 error.
Any ideas on what is going wrong would be greatly appreciated.

I think the problem is src/main/java folder , you said you manually create it. so you did not add it to Source after create it?
Update
i just import the code to eclipse,and i modify the Web Module Path,and it worked. here is the snap:
and the test url
hope this is useful.

Related

Trying to deploy a Spring Boot web app using a JAR file, however am getting 404 NOT_FOUND errors on my JSPs

First post on here and I'm fairly new to JAVA so please keep that in mind ;) I've spent literally days trying to solve my problem and am running out of patience. Here's the deal : I've got a Spring Boot web app that I've successfully deployed on Digital Ocean by running a Tomcat Server and deploying a WAR file on my cloud VM. Everything was working fine with that set up when my app wasn't a Spring Boot app. Since then I've changed it to Spring Boot (added Spring Security etc.) and would like to deploy a JAR file which has Tomcat built into it which I was told is simpler and the better way of doing things. After creating my JAR file via my IntelliJ IDE, using Maven clean and build I'm able to run the app successfully on my windows machine command line which I've confirmed runs : localhost:8080/login spits out a message to the console so I know it's in my controller as well as I can see a connection to my DB. The issue is my JSPs files aren't loading and am seeing the below in my console:
Errors
Forwarding to [/WEB-INF/view/login.jsp]
Completed 404 NOT_FOUND
After many hours I've realized that when I open my JAR file via WinRAR, the JAR file is missing my files that I had under my webapp directory in IntelliJ. Since this is a stand alone executable JAR, these files need to be located somewhere in my JAR, right?
Two questions I guess:
1.Do I need to do something special to get my webapp files added to the JAR during the build?
2.Can I just alter the JAR manually and place them in there? If so, where should I locate them so that they can be accessed and I won't get the 404 errors anymore?
Thanks all for your help. Much appreciated.

Problem with creating a Spring Boot Application

i am still a beginner with spring boot, and i have a bunch of questions.
First of all, do i have to download maven in my pc and add it to my pc path envirement to make spring boot work correctly ?
Secondly, Spring boot wasn't able to work, was doing a hello world app and there were lot of errors on the console one of them is "SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".. why that ? i looked for the error and followed some mvn command line steps "mvn dependency:purge-local-repository", and my app finally worked.. but do i have to run this command everytime i create a spring boot app ? isn't everything supposed to be alright since it's only a hello world app ? ..
Thank you
Yes, you need to have installed maven or gradle in order to run your application. And it needs to be reachable, so you have to configure your system variables accordingly.
You can find more details here.
As per the maven error, maven keeps all the artifacts you need to run your application in a shared folder with all versions, sometimes maven could have corrupted files or a mismatch in version so you need to purge the repository and download artifacts again.
You can find a more detailed answer here.
Even when you are coding a simple application, spring-boot bring up a lot of code for supporting operations you may require, such code is self configured and hidden.

Spring Boot 1.3 : error on init.d service but "java -jar" working

I have an app that runs properly when I execute java -jar myapp.jar but when I link it to run as process I'm getting 404 error. So I made an gitHub repository only with the relevant classes to show you the error. Could you try to reproduce it?
Here is the code
https://github.com/alephlm/spring-boot-1.3-error-executable-service
I'm using ubuntu 14.04
Thanks.
Your maven script never explicitly packages the webapp contents, and even if it did, Tomcat will not pick it up. But, there is a work around, do the following:
create a META-INF/resources in your resources folder (e.g. src/main/resources/META-INF/resources/)
now move everything from under webapp to your new META-INF/resources folder (e.g. ..META-INF/resources/WEB-INF/views/hello.jsp)
I recently read about it on Gunnar's blog. The great thing about this solution is that you don't have to mess with the maven copying resources, it will automatically get picked up since it's in src/main/resources.

Update startup.bat tomcat7

I'm working on tomcat7 project on Eclipse (only the manager part). I get the project here. This is the first time I'm working on this kind of project, and when I turn on the server and look at my page, nothing has changed (It was only a test changing some string in java/org/catalina/manager/LocalStrings_fr.properties).
I guess the startup.bat is not updated or something like that. Nothing about it on Google (else the build of the project with Linux command line, but I'm working on Windows).
Does anyone knows what have to be done?
Edit: It seems that my question is not easyly understandable, so I put some pictures to explain:
I work on Tomcat7 in my workspace:
I try to change the file (just to test, I need to work on servlets too).
When I change the language file as:
htmlManagerServlet.title=Gestionnaire d''applications WEB Tomcat TEST
instead of
htmlManagerServlet.title=Gestionnaire d''applications WEB Tomcat
I get nothing after re-run the server:
I hope it's more easy to understand.
Thanks

Maven build war doesn't work properly on Tomcat 7

I've been working on a web app that and here's me configuration before I get started telling my story.
Configuration: IntelliJ IDEA 11 + Java 7 + (Maven + Jetty 8.0.1).
When I clean and build my app on intelliJ, everything works as expected and nothing goes wrong; pages load, rendering are perfectly fine. Then I use -mvn clean package command to build my project so I'll test my app on Tomcat 7.
However, when I deploy my application to Tomcat, some pages aren't as I saw on my maven build: renderings doesn't work properly, styling is a little bit deprecated and so on...
Even some pages doesn't load fully when I check on firebug.
I wish someone encountered a similar issue; this thing is making me crazy... If you need any logs or anything just name it.
Thank you.
Apperently, there's always nuances that you miss sometimes and browsers keep extensive data of the pages you browser. I've just cleared all of my browsers caches and now everything works perfectly!.. So if you encounter something similar, be sure to clear your browser cache.

Categories