已部署至WildFly 9.x仍遇404错误,求解决方案
Hey there, let’s work through this 404 issue step by step—since you’ve confirmed deployment is successful via logs and screenshots, the problem is almost certainly tied to how you’re accessing the app or a small configuration detail you might have missed. Here are the most common fixes to check:
Double-check your context root
WildFly uses a context root to route requests to your application. By default, this is usually the name of your WAR file (without the.warsuffix), but if you set a custom root injboss-web.xmlor your project’s deployment settings, that’s the path you need to use.- To confirm: Look for a line in your WildFly console logs like
Registered web context: /your-app-context—append this to your base URL (e.g.,http://localhost:8080/your-app-context). - In Eclipse, you can also verify this by checking your project properties under Deployment Assembly or WildFly Deployment Settings.
- To confirm: Look for a line in your WildFly console logs like
Verify your servlet or resource mapping
If your HelloWorld app uses servlets, make sure theurl-patterninweb.xml(or annotation-based mapping like@WebServlet) matches what you’re accessing.- For example, if your servlet is annotated with
@WebServlet("/hello"), your full request URL should behttp://localhost:8080/your-app-context/hello. - If you’re using
web.xml, check the<servlet-mapping>section to confirm the pattern aligns with your request.
- For example, if your servlet is annotated with
Watch for case sensitivity and typos
WildFly is case-sensitive when handling URLs—so/Hellois not the same as/hello. Triple-check that every part of your request URL matches exactly what’s configured in your app.Confirm the correct port is being used
By default, WildFly uses port 8080 for HTTP, but if you modifiedstandalone.xmlordomain.xmlto use a different port, you need to include it in your URL. Look for a log line likeHttpListener startedto confirm the active port number.Check for a default root resource
If you’re trying to access the app’s root URL (e.g.,http://localhost:8080/your-app-contextdirectly), make sure there’s anindex.html,index.jsp, or a servlet mapped to/(the root path). Without a default resource at the root, you’ll get a 404 even if the app is deployed.Inspect the deployed content
Navigate to WildFly’s deployment directory (typicallywildfly-9.x/standalone/deployments/) and check if your WAR file is expanded into a folder. Inside that folder, confirm your static files (HTML/JSP) are in the root of the WAR, and compiled classes are inWEB-INF/classes—missing or misplaced files can cause 404s even with a successful deployment log.
From my experience, the context root mismatch or incorrect servlet mapping are the top two culprits here. Start with those checks first—they’re easy to overlook but fix most cases of this issue!
内容的提问来源于stack exchange,提问作者Dan

