Spring+Hibernate无前端REST服务部署WebSphere后访问404错误求助
Hey there, let's break down why you're hitting that 404 on WebSphere with your Spring+Hibernate backend. Since your debug breakpoints aren't triggering, the request isn't even reaching your controllers—so let's start with the most common culprits:
First things first: double-check the context root you set when deploying to WebSphere, and make sure your request URL lines up with it.
- In Eclipse, right-click your project →
Properties→Web Project Settingsto confirm the context root value. - In the WebSphere console, go to
Applications→ Your App →Configuration→Context Rootto verify it matches what you're using in your browser. - For example: if your context root is
/mybackendand your REST controller maps to/users, your full request URL should behttp://<server>:<port>/mybackend/users—missing any part here will throw a 404.
If Spring's application context fails to initialize, your controllers won't be registered at all. Here's how to check:
- If you're using annotation-based config, make sure your root configuration class (like one with
@SpringBootApplicationor@Configuration + @ComponentScan) covers all your packages. For example:@Configuration @ComponentScan(basePackages = {"com.yourapp.entities", "com.yourapp.services", "com.yourapp.dao", "com.yourapp.controllers"}) public class AppConfig { } - Check WebSphere's
SystemOut.log(found inprofiles/<profile-name>/logs/<server-name>/). Look for lines likeRefreshing org.springframework.context.annotation.AnnotationConfigApplicationContext—if you don't see this, Spring isn't starting up, which means no routes are registered.
The DispatcherServlet is the entry point for all Spring MVC requests—if it's mapped incorrectly, requests won't reach your controllers.
- If you're using a traditional
web.xml, verify the servlet mapping:<servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> <!-- Or /api/* if you prefix all endpoints --> </servlet-mapping> - For Spring Boot, the default mapping is
/, but if you setserver.servlet.context-pathinapplication.properties, make sure your request includes that path.
WebShipere comes with its own bundled libraries, which can clash with your project's dependencies (like Spring or Hibernate versions).
- Mark container-provided dependencies as
providedin yourpom.xml(or build.gradle) to avoid conflicts:<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> - In the WebSphere console, go to your app →
Classloading and update detection, set the Class loader order toClasses loaded with local class loader first (parent last)—this often fixes issues where WebSphere's older libraries override your project's ones.
Since your breakpoints aren't triggering, confirm your debug setup is working:
- Check Eclipse's Debug view to ensure it's connected to the WebSphere server (you should see the server listed under "Debug").
- Disable JIT optimization in WebSphere by adding these JVM arguments at startup:
-Xdebug -Xnoagent -Djava.compiler=NONE—sometimes optimization skips code where your breakpoints are set. - Make sure your breakpoints are on concrete controller methods (not interfaces or abstract classes) that should actually receive requests.
Pro tip: Always start by checking WebSphere's SystemOut.log and SystemErr.log—they'll almost always have error messages or warnings that point you to the root cause (like a missing dependency, failed Spring bean initialization, or servlet mapping errors).
内容的提问来源于stack exchange,提问作者SimonaC

