gpt4 book ai didi

java - 除了白色标签错误页面之外什么也看不到 - Spring boot + hibernate

转载 作者:行者123 更新时间:2023-12-02 13:22:57 26 4
gpt4 key购买 nike

没有映射到我的请求[/]引用方法 allHotels()以下是我的应用程序和 Controller 类。

应用程序类

@SpringBootApplication(scanBasePackages = {"comexam.example"})
@EnableAutoConfiguration
public class Application
{
public static void main(String[] args) throws ParseException
{
SpringApplication.run(Application.class, args);
}

}

HotelController.class

@RestController
public class HotelController
{
@Autowired HotelService hotelService;

@RequestMapping(value = "/hotels/", method = RequestMethod.GET)
public ResponseEntity<List<Hotel>> allHotels() {
List<Hotel> hotels = hotelService.getAllHotels();
if (hotels.isEmpty()) {
return new ResponseEntity<List<Hotel>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND
}
return new ResponseEntity<List<Hotel>>(hotels, HttpStatus.OK);
}

}

以下是我得到的错误堆栈。

2017-04-19 17:17:23.729  INFO 5808 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-04-19 17:17:23.730 INFO 5808 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.36
2017-04-19 17:17:23.836 INFO 5808 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-04-19 17:17:23.836 INFO 5808 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1646 ms
2017-04-19 17:17:24.077 INFO 5808 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-04-19 17:17:24.080 INFO 5808 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-04-19 17:17:24.081 INFO 5808 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-04-19 17:17:24.081 INFO 5808 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-04-19 17:17:24.081 INFO 5808 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-04-19 17:17:24.277 INFO 5808 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@382db087: startup date [Wed Apr 19 17:17:22 IST 2017]; root of context hierarchy
2017-04-19 17:17:24.334 INFO 5808 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hotels/],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<comexam.example.model.Hotel>> comexam.example.controller.HotelController.allHotels()
2017-04-19 17:17:24.337 INFO 5808 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-04-19 17:17:24.338 INFO 5808 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-04-19 17:17:24.365 INFO 5808 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-19 17:17:24.365 INFO 5808 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-19 17:17:24.402 INFO 5808 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-19 17:17:24.497 INFO 5808 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-04-19 17:17:24.582 INFO 5808 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)

最佳答案

您已指定要扫描的,因此您的 Controller 类必须位于“it.exam.training”包内的某个位置。

@SpringBootApplication(scanBasePackages = {"it.exam.training"})

要解决此问题,请将 HotelController 类移至“it.exam.training.controller”。

关于java - 除了白色标签错误页面之外什么也看不到 - Spring boot + hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43495260/

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