我有一个基本的SpringBoot应用程序。使用Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎以及作为可执行JAR文件的软件包。
这是主要的课程
@SpringBootApplication public class TdkApplication { public static void main(String[] args) { SpringApplication.run(TdkApplication.class, args); } }
这是一个控制器
@Controller public class MockupIndexController { @RequestMapping("/mockup/index") public String welcome(Map<String, Object> model) { return "mockups/index"; } }
这是我的 pom.xml
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
我假设在扫描期间未找到您的控制器类,因为它位于默认情况下不会被扫描的软件包中。我猜您的应用程序位于com.tdk.app之类的内容中,而您的控制器位于com.tdk.controller之类的内容中,对吗?如果是,只需将应用程序上移至com.tdk,您的问题就可以解决。