gpt4 book ai didi

spring-boot - Spring Boot找不到处理程序方法

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

我有一个基本的SpringBoot应用程序。使用Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎以及作为可执行JAR文件的软件包。

这是主要的类(class)

@SpringBootApplication
public class TdkApplication {
public static void main(String[] args) {
SpringApplication.run(TdkApplication.class, args);
}
}

这是一个 Controller
@Controller
public class MockupIndexController {
@RequestMapping("/mockup/index")
public String welcome(Map<String, Object> model) {
return "mockups/index";
}
}

这是我的 pom.xml
 <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.tdk.iot.core</groupId>
<artifactId>tdk-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

但是,当我将其放在URL中时:
http://localhost:8080/mockup/index

我在控制台中收到以下日志
o.s.web.servlet.DispatcherServlet        : Servlet 'dispatcherServlet' configured successfully
o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/mockup/index]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /mockup/index
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/mockup/index]
o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/mockup/index] are [/**]
o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/mockup/index] are {}
o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/mockup/index] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@8b91134]]] and 1 interceptor
o.s.web.servlet.DispatcherServlet : Last-Modified value for [/mockup/index] is: -1
o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
o.s.web.servlet.DispatcherServlet : Successfully completed request
o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error

最佳答案

我假设在扫描过程中未找到您的 Controller 类,因为它位于默认情况下不会被扫描的软件包中。我猜您的应用程序位于com.tdk.app之类的内容中,而您的 Controller 位于com.tdk.controller之类的内容中,对吗?如果是,只需将应用程序上移至com.tdk,您的问题就可以解决。

关于spring-boot - Spring Boot找不到处理程序方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43747742/

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