Win a copy of Emmy in the Key of Code this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Spring MVC project in NetBeans

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
definite greenhorn here. hoping i can get some help.

i'm doing a udemy course on spring which uses eclipse for all projects. i really like netbeans and have been trying to get it to work with the course material.

normal projects work fine, but i can't get a spring mvc project to work in netbeans. it gets a 404 error. can anyone here help look at this project to try to figure out what the problem is?

 
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Have you configured a web server in NetBeans? Can you show us your context.xml and your web.xml or main configuration class if you're using annotation based configuration? What URL are you using to reach the web application?
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for reply and for your questions.

yes, i think i have successfully added a tomcat server and have it working (pic attached).

server.PNG
[Thumbnail for server.PNG]
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and here are the files. i couldn't find a way to upload them due to disallowed file types.

any help would be much appreciated


context.xml


spring-mvc-demo-servlet.xml


web.xml



Controller class
 
Stephan van Hulst
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have an application class in the com.luv2code.springdemo package? It's not necessary, but if you do, I'd like to see the code.

What URL are you using to access your application?
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks. no, the only class in the package com.luv2code.springdemo is HomeController.java

fyi, i recreated this project from scratch after successfully building and running it in eclipse as part of my course.

i never understood why in spring-mvc-demo-servlet.xml the scanning is set up as follows:



seems to me it should include .mvc at the end of the package name as follows

maybe the scanning for components recursively scans subdirectories.

anyway, making that change still results in 404 error
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, and when running the program the address in the browser is:

http://localhost:8080/spring-mvc-demo/
 
Stephan van Hulst
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, component scanning is recursive.

Can you show us your Catalina log? It should be displayed in one of the ouput windows when you start Tomcat by debugging your application through NetBeans.
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this should be the catalina log i think

 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
let me know if there's a different way i should post long code. i just bought some pie to be able to post the catalina log because it seemed like the best option
 
Stephan van Hulst
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the exact name of the WAR file that you've deployed to Tomcat?
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi this is the name i found in the dist folder of my project:

spring-mvc-demo.war

i actually don't use it to deploy the project. i'm just clicking the run button in netbeans.
 
Stephan van Hulst
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, NetBeans copies the WAR to Tomcat, which will auto-deploy it if that setting is enabled (which it usually is). The reason I asked is because auto-deploy uses the name of the WAR as the context path.

Hmm I can't see why it doesn't work. I'll have some time to try out your code in my IDE later. Did you create a normal NetBeans Web project, or are you using Maven?
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for letting me know. it's a so called Java Web Web Application

here's a pic of how i set it up when creating new project. although i've heard of Maven, i don't even know what it is yet
netbeans.PNG
[Thumbnail for netbeans.PNG]
 
Stephan van Hulst
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final questions before I try it out. Did you download and register Tomcat in NetBeans yourself, or did it come bundled with NetBeans? Have you changed any of the Tomcat settings since you've first installed it?
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for your question. i manually added Tomcat to Netbeans using the instructions on this page

https://javapointers.com/tutorial/add-tomcat-server-netbeans/

and i haven't changed any of the settings for Tomcat in Netbeans
 
Stephan van Hulst
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to assume you're using Tomcat 8. Can you tell me which version of the JDK your project uses?
 
Mack Joseph
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks like Tomcat 9 and Java SDK8
Capture.PNG
[Thumbnail for Capture.PNG]
Capture2.PNG
[Thumbnail for Capture2.PNG]
 
Stephan van Hulst
Saloon Keeper
Posts: 10746
229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, few more questions:

  • Are the stray dashes in the XML you posted earlier (such as before <servlet> on line 13 of your web.xml) a result of you copying your code to this conversation, or are they also there in the original XML?
  • Can you show the contents of the lib folder under WEB-INF? What libraries did you add to the project and how did you add them?
  • Can you show the contents of the index.html and main-menu.jsp files?
  • When you selected a web server for your application, what Java EE version did you specifiy? JavaEE 7 Web?
  •  
    Mack Joseph
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi my system suffered 3 drive failures when trying to install a new psu  

    i should be back to normal operations within a few days if not less and will get back on this with you.  thanks a lot for the help so far
     
    Mack Joseph
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    the dashes appear to the be result of pasting the code here. they're not in the original file.

    i've attached a screenshot of lib folder under WEB-INF "Capture"

    i added the entire contents of spring-framework-5.1.9.RELEASE libs folder to a folder i created called lib under WEB-INF. and then i selected the properties for the project, libraries, and Add JAR/Folder as seen in "Capture2"

    index.html:


    and main-menu.jsp



    When you selected a web server for your application, what Java EE version did you specifiy? JavaEE 7 Web?

    yes, that's right
    Capture.PNG
    [Thumbnail for Capture.PNG]
    Capture2.PNG
    [Thumbnail for Capture2.PNG]
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 10746
    229
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Good news, I can reproduce your problem.

    Bad news, I haven't figured out the exact reason for the issue yet.

    Let me play with it a bit and I'll get back to you when I know more.
     
    Mack Joseph
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    that is indeed good news



     
    I'm still in control here. LOOK at this tiny ad!
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!