gpt4 book ai didi

java - 在 servlet 'DispatcherServlet' : using default 中找不到 HandlerMappings

转载 作者:行者123 更新时间:2023-12-02 17:58:42 24 4
gpt4 key购买 nike

我正在尝试使用 Spring MVC 的 webapp 基本项目(入门项目 STS 3.7.0)。 Java 1.7
WebConfig.java

package com.terafast;

import org.springframework.context.annotation.Bean;
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.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.terafast")
public class WebConfig extends WebMvcConfigurerAdapter {

@Bean
public InternalResourceViewResolver getInternalViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/view/");
resolver.setSuffix(".jsp");

return resolver;
}
}

WebAppInitializer.java

package com.terafast;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class WebAppInitializer implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("*.html");
}

private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation("com.terafast.WebConfig");

return context;
}

}

家庭 Controller

package com.terafast.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {
@RequestMapping(value = "/index")
public String index(Model model) {

return "welcome";
}
}

我在 webapp/WEB-INF/view/路径中创建了welcome.jsp。当我将项目作为服务器运行时,我在 http://localhost:8080/TEM/ 上什么也没有得到。 。当我使用http://localhost:8080/TEM/index.html时我也什么也没有得到。 .

18:18:29.911 [http-nio-8080-exec-4] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/TEM/index] in DispatcherServlet with name 'DispatcherServlet' 
18:18:29.911 [http-nio-8080-exec-4] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request

enter image description here有人可以解释一下问题是什么吗?

最佳答案

嘿,我遇到了同样的问题,你可以做的是转到你的项目属性>> DeploymentAssembly,然后添加你的 DispatcherServlet 库,无论它在哪里。

这将解决您的问题。

关于java - 在 servlet 'DispatcherServlet' : using default 中找不到 HandlerMappings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31561643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com