веб — проект java spring mvc не может найти маршрут-запрошенный ресурс недоступен

#java #spring-boot #spring-mvc

Вопрос:

Этот проект Spring MVC для начинающих был настроен с использованием конфигурации на основе Java, и структура проекта выглядит так, как показано ниже:

введите описание изображения здесь

Передний контроллер выглядит следующим образом:

 public class SiteFrontController extends AbstractAnnotationConfigDispatcherServletInitializer
{
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] {MvcConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] {"/"};
    }
}
 

В ‘MvcConfig.java» как показано ниже:

 package com.tz.web;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
@ComponentScan("com.tz")
public class MvcConfig implements WebMvcConfigurer
{

}
 

The single controller is as below:

 package com.tz.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class AddController 
{
    @RequestMapping("/add")
    public ModelAndView add(@RequestParam("o1") int num1, @RequestParam("o2") int num2) 
    {
        ModelAndView mv = new ModelAndView();
        int k = num1   num2;
        mv.addObject("result", k);
        mv.setViewName("result.jsp");
        return mv;
    }
}
 

To call this controller/route, here is the form:

 <form action="add">
  <input type="text" name="o1"><br>
  <input type="text" name="o2"><br>
  <input type="submit">
</form>
 

Запуск выполняется на Tomcat v10.0, он запускается, но ему все равно не удается найти маршрут контроллера, он продолжает говорить:

 Message The requested resource [/jproj/add] is not available

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.