【问题标题】:No mapping found error in dispatcher servlet调度程序 servlet 中未找到映射错误
【发布时间】:2018-09-12 07:56:21
【问题描述】:

我是 Spring MVC 的初学者,在尝试创建 Spring MVC 应用程序时,我收到以下 错误

no mapping found for http request with uri [/SpringMVCHibernateCRUD] in dispatcherservlet 'appServlet'

以下是文件:

Web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>


<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

servlet-context.xml

      <context:component-scan base-package="com.jwt" />

<!-- Getting Database properties -->
<context:property-placeholder location="classpath:application.properties" />

<mvc:annotation-driven />

<!-- Specifying the Resource location to load JS, CSS, Images etc -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- View Resolver -->
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/" />
    <property name="suffix" value=".jsp" />
</bean>

<!-- Transaction -->
<bean id="transactionManager"

 class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
 </beans>

编辑:

控制器

 @Controller
 public class EmployeeController {

 private static final Logger logger = Logger
        .getLogger(EmployeeController.class);

 public EmployeeController() {
    System.out.println("EmployeeController()");
 }

 @Autowired
 private EmployeeService employeeService;

 @RequestMapping(value = "/")
 public ModelAndView listEmployee(ModelAndView model) throws IOException {
    List<Employee> listEmployee = employeeService.getAllEmployees();
    model.addObject("listEmployee", listEmployee);
    model.setViewName("home");
    return model;
 }

/ 更改为/* 并没有解决问题,我已经在控制器上添加了@controller 注释。有人可以帮我解决这个问题吗?

【问题讨论】:

  • 你能提供控制器的代码吗?你有像 @RequestMapping(value = "/SpringMVCHibernateCRUD" ) 这样的 URL 映射吗?
  • 我们能看到控制器类吗?
  • 请包含您的控制器类。
  • @SumeshTG 已编辑..
  • @achAmháin 已编辑

标签: java spring spring-mvc


【解决方案1】:

用这个改变你的 servlet 映射并尝试;

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

在您的 web.xml 中,您的 url-pattern 仅是 / 。更改为 /* 以向任何 url 发送请求。

【讨论】:

  • 做到了..同样的问题
  • 还要在你的控制器类上添加@requestmapping 和相关的映射
  • 添加了..还是同样的问题
【解决方案2】:

试试下面:

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

【讨论】:

    【解决方案3】:

    感谢您的回答,显然一个简单的清理和构建解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-10
      • 2014-09-28
      • 2015-06-12
      • 2021-08-16
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多