Intellij Springboot启动时出现问题 [英] Intellij Springboot problems on startup

查看:218
本文介绍了Intellij Springboot启动时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Spring Boot真的很陌生,因此我从一些教程开始创建一个简单的Rest示例(我的最终目标是将其与mongodb集成,但是我需要开始!). 我使用Spring Initializr在IntelliJ上创建了一个新项目,并选择了Web和Mongodb作为功能. 然后我只添加了一个类,

I am really new with spring boot, so I started with some tutorials to create a simple Rest example (my final goal is to integrate it with mongodb, but I need to start!). I created a new project on IntelliJ with Spring Initializr and choosed Web and Mongodb as features. Then I added only a class,

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

@RequestMapping("/")
public String index() {
    return "Greetings from Spring Boot!";
}

}

运行项目时,控制台为

 2018-09-03 20:08:33.139  INFO 1363 --- [           main] 
 test.test.TestApplication                : Starting TestApplication on 
 MacBook-Pro-di-Stefano.local with PID 1363 
 (/Users/stefanomiceli/IdeaProjects/test/target/classes started by 
 stefanomiceli in /Users/stefanomiceli/IdeaProjects/test)
 2018-09-03 20:08:33.141  INFO 1363 --- [           main] 
 test.test.TestApplication                : No active profile set, 
 falling back to default profiles: default
 2018-09-03 20:08:33.173  INFO 1363 --- [           main] 
 ConfigServletWebServerApplicationContext : Refreshing 

org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@15713d56: startup date [Mon Sep 03 20:08:33 PDT 2018]; root of context hierarchy

 WARNING: An illegal reflective access operation has occurred
 WARNING: Illegal reflective access by 
 org.springframework.cglib.core.ReflectUtils$1 
 (file:/Users/stefanomiceli/.m2/repository/org/springframework/spring- 
 core/5.0.8.RELEASE/spring-core-5.0.8.RELEASE.jar) to method 


java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)

 WARNING: Please consider reporting this to the maintainers of 
 org.springframework.cglib.core.ReflectUtils$1
 WARNING: Use --illegal-access=warn to enable warnings of further 
 illegal reflective access operations
 WARNING: All illegal access operations will be denied in a future 
 release
 2018-09-03 20:08:33.950  INFO 1363 --- [           main] 
 o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with 
 port(s): 8080 (http)
 2018-09-03 20:08:33.969  INFO 1363 --- [           main] 
 o.apache.catalina.core.StandardService   : Starting service [Tomcat]
 2018-09-03 20:08:33.969  INFO 1363 --- [           main] 
 org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: 
 Apache Tomcat/8.5.32
 2018-09-03 20:08:33.972  INFO 1363 --- [ost-startStop-1] 
 o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat 
 Native library which allows optimal performance in production 
 environments was not found on the java.library.path: 


 [/Users/stefanomiceli/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]

 2018-09-03 20:08:34.021  INFO 1363 --- [ost-startStop-1] o.a.c.c.C. 
 [Tomcat].[localhost].[/]       : Initializing Spring embedded 
 WebApplicationContext
 2018-09-03 20:08:34.021  INFO 1363 --- [ost-startStop-1] 
 o.s.web.context.ContextLoader            : Root WebApplicationContext: 
 initialization completed in 852 ms
 2018-09-03 20:08:34.059  INFO 1363 --- [ost-startStop-1] 
 o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet 
 mapped to [/]
 2018-09-03 20:08:34.061  INFO 1363 --- [ost-startStop-1] 
 o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
 'characterEncodingFilter' to: [/*]
 2018-09-03 20:08:34.062  INFO 1363 --- [ost-startStop-1] 
 o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
 'hiddenHttpMethodFilter' to: [/*]
 2018-09-03 20:08:34.062  INFO 1363 --- [ost-startStop-1] 
 o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
 'httpPutFormContentFilter' to: [/*]
 2018-09-03 20:08:34.062  INFO 1363 --- [ost-startStop-1] 
 o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 
 'requestContextFilter' to: [/*]
 2018-09-03 20:08:34.143  INFO 1363 --- [           main] 
 o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path 
 [/**/favicon.ico] onto handler of type [class 
 org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
 2018-09-03 20:08:34.310  INFO 1363 --- [           main] 
 s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for 
 @ControllerAdvice: 



org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@15713d56: startup date [Mon Sep 03 20:08:33 PDT 2018]; root of context hierarchy

 2018-09-03 20:08:34.344  INFO 1363 --- [           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.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)

 2018-09-03 20:08:34.345  INFO 1363 --- [           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.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

 2018-09-03 20:08:34.362  INFO 1363 --- [           main] 
 o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path 
 [/webjars/**] onto handler of type [class 
 org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
 2018-09-03 20:08:34.362  INFO 1363 --- [           main] 
 o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto 
 handler of type [class 
 org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
 2018-09-03 20:08:34.550  INFO 1363 --- [           main] 
 org.mongodb.driver.cluster               : Cluster created with 
 settings {hosts=[localhost:27017], mode=SINGLE, 
 requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', 
 maxWaitQueueSize=500}
 2018-09-03 20:08:34.582  INFO 1363 --- [localhost:27017] 
 org.mongodb.driver.connection            : Opened connection 
 [connectionId{localValue:1, serverValue:55}] to localhost:27017
 2018-09-03 20:08:34.585  INFO 1363 --- [localhost:27017] 
 org.mongodb.driver.cluster               : Monitor thread successfully 
 connected to server with description 
 ServerDescription{address=localhost:27017, type=STANDALONE, 
 state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 0, 
 1]}, minWireVersion=0, maxWireVersion=7, maxDocumentSize=16777216, 
 logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1582641}
 2018-09-03 20:08:34.739  INFO 1363 --- [           main] 
 o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX 
 exposure on startup
 2018-09-03 20:08:34.768  INFO 1363 --- [           main] 
 o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 
 8080 (http) with context path ''
 2018-09-03 20:08:34.772  INFO 1363 --- [           main] 
 test.test.TestApplication                : Started TestApplication in 
 1.834 seconds (JVM running for 7.413)

但是当我继续执行localhost:8080/时,会出现404错误.我在 helloworld 中做错了什么?在运行该应用程序之前,我应该做些什么吗?

But when I go on localhost:8080/ I get 404 error. What did I do wrong in my helloworld? Is there anything that should I make before running the application?

推荐答案

您的包结构错误:

prova.HelloController

test.test.TestApplication

HelloController必须处于同一级别或低于TestApplication.

The HelloController must be on the same level or below TestApplication.

这篇关于Intellij Springboot启动时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆