gpt4 book ai didi

java - 错误提示 : No mapping found for HTTP request with URI in DispatcherServlet due to Maven dependency

转载 作者:行者123 更新时间:2023-12-02 02:08:00 25 4
gpt4 key购买 nike

我正在尝试在 java 配置中使用 hibernate 在 spring 中使用角色库进行身份验证和授权。当我运行服务器时,它给出错误,指出在 servlet 中未找到 URI 的映射。

public class ShoppingInitializerWeb implements WebApplicationInitializer {

public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(ShoppingServletConfig.class);
ctx.setServletContext(container);
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));

servlet.setLoadOnStartup(1);
servlet.addMapping("/*");

}
}

ShoppingServletConfig.java

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "com.project.shopping")
public class ShoppingServletConfig extends WebMvcConfigurerAdapter{
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/ui/view/");
viewResolver.setSuffix(".jsp");

return viewResolver;
}

WebConfigStatic.java

@EnableWebMvc
@Configuration

@ComponentScan(basePackages="com.project.shopping")
public class WebConfigStatic extends WebMvcConfigurerAdapter{
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/js/**").addResourceLocations("/ui/js/");
registry.addResourceHandler("/css/**").addResourceLocations("/ui/css/");
registry.addResourceHandler("/*.html/**").addResourceLocations("/ui/view/");
}
}

这是我的 Controller :

@Controller
@RequestMapping("/")
public class UserController {
@RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET)
public String homePage(ModelMap model) {
model.addAttribute("user", getPrincipal());
return "welcome";
}

我在 webapp/WEB-INF/ui/view 中有welcome.jsp

这是控制台中的错误:

WARNING: No mapping found for HTTP request with URI [/Shoping/home] in DispatcherServlet with name 'dispatcher'

我查找了所有相关错误并尝试解决,但无法解决。

最佳答案

我在 Spring 项目中遇到了相同的项目,我尝试了所有可能的方法,但没有解决方案不适用于该项目,但是,最终我得到了解决方案。

将 Maven 依赖项添加到项目部署程序集中后,我的项目完美运行。所以,你可以尝试下面的过程,如果你的代码是完美的,它应该可以工作。

Right click on Project then select Properties > Deployment Assembly > then click add button > Java Build path entries > Select Maven dependencies > click Finish button.

然后更新maven项目,然后mvn clean install ...然后运行。

我希望它会起作用。

关于java - 错误提示 : No mapping found for HTTP request with URI in DispatcherServlet due to Maven dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50463043/

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