You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring MVC报错No mapping found for HTTP request with URI 配置求助

Troubleshooting "No mapping found for HTTP request with URI" in Spring MVC on WebLogic

Hey there! Let's break down this common Spring MVC issue you're hitting with your first app on WebLogic. The good news is your DispatcherServlet initialized successfully—so we can cross off major startup failures right away. Let's walk through the most likely configuration gaps step by step:

1. Verify Controller Annotations & Request Mapping Paths

  • First, double-check that your controller class is annotated with @Controller (or @RestController if you're building a REST app). Without this, Spring won't recognize it as a request handler.
  • Make sure your @RequestMapping path exactly matches the URI you're requesting—WebLogic is case-sensitive by default, so /Hello vs /hello will be treated as different paths. For example:
    @Controller
    @RequestMapping("/greeting")
    public class GreetingController {
        @RequestMapping("/sayHello")
        public String sayHello(Model model) {
            model.addAttribute("message", "Hello World!");
            return "helloView";
        }
    }
    
    This would expect a request to http://your-server/your-app-context/greeting/sayHello (more on app context in step 4).

2. Confirm DispatcherServlet Mapping in web.xml

  • Your web.xml must correctly map the DispatcherServlet to handle incoming requests. Common pitfalls here include:
    • Using a too-restrictive url-pattern (like *.do) but forgetting to append the suffix to your request URI.
    • Using <url-pattern>/</url-pattern> (which is correct for catching all requests) but not configuring static resource handling (if you need it). For Spring 4.x, add <mvc:default-servlet-handler/> to your dispatcher config to let the container handle static files.
  • Example valid web.xml snippet:
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    

3. Ensure Spring Scans Your Controller Packages

  • In your dispatcher-servlet.xml (or Spring config file), two key lines are required:
    • <context:component-scan base-package="com.your.package.controllers"/>: This tells Spring to scan the specified package (and subpackages) for annotated components like controllers. If the package path is wrong, Spring will never find your controller.
    • <mvc:annotation-driven/>: Enables support for @RequestMapping and other Spring MVC annotations—this is easy to forget and a common culprit!
  • Example config snippet:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd
               http://www.springframework.org/schema/mvc
               http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
        <context:component-scan base-package="com.yourproject.controller"/>
        <mvc:annotation-driven/>
    
        <!-- View resolver config, etc. -->
    </beans>
    

4. Check WebLogic Deployment Context Root

  • When deploying to WebLogic, your app gets a context root (e.g., /my-first-spring-app). This prefix must be included in your request URI. For example, if your controller maps to /greeting/sayHello, the full request URL would be http://weblogic-server:port/my-first-spring-app/greeting/sayHello.
  • You can verify the context root in the WebLogic Console: Go to Deployments > Your App > Configuration > General to check or adjust it.

5. Resolve Jar Version Conflicts with WebLogic

  • WebLogic may include its own version of Spring libraries, which can clash with the Spring 4.3.14 jars in your app. To fix this, add a weblogic.xml file in WEB-INF to tell WebLogic to prefer your app's jars:
    <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
        <container-descriptor>
            <prefer-application-packages>
                <package-name>org.springframework.*</package-name>
            </prefer-application-packages>
        </container-descriptor>
    </weblogic-web-app>
    

6. Confirm Controller Classes Are Packaged Correctly

  • Sometimes Eclipse doesn't compile or package your controller classes into the WAR. Open your deployed WAR file (or check the WEB-INF/classes directory in your Eclipse deployment) to ensure your controller .class files are present. If not, double-check your Eclipse build path settings to make sure the source folder is marked correctly.

If you've gone through all these steps and still hit the issue, sharing your controller code, web.xml, and dispatcher-servlet.xml snippets would help pinpoint the problem faster!

内容的提问来源于stack exchange,提问作者r-developer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:01:04