Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

spring boot - Intellij Springboot problems on startup

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!";
}

}

When I run the project, the console is

 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)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your package structure is wrong:

prova.HelloController

test.test.TestApplication

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...