<!-- (you don't need this if you are using a .RELEASE version) --> <repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </pluginRepository> </pluginRepositories> </project>
It’s a very common use case to have Controllers implement a REST API, thus serving only JSON, XML or custom MediaType content. For convenience, instead of annotating all your @RequestMapping methods with @ResponseBody, you can annotate your Controller Class with @RestController.
@RestController is a stereotype annotation that combines @ResponseBody and @Controller. More than that, it gives more meaning to your Controller and also may carry additional semantics in future releases of the framework.
2016-02-20 18:57:49.387 INFO 2800 --- [ main] Example : Starting Example on larrydeMacBook-Pro.local with PID 2800 (/Users/larry/IdeaProjects/java/springboot/target/classes started by larry in /Users/larry/IdeaProjects/java/springboot)
2016-02-20 18:57:50.116 INFO 2800 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2016-02-20 18:57:50.124 INFO 2800 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2016-02-20 18:57:50.125 INFO 2800 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30 2016-02-20 18:57:50.298 INFO 2800 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2016-02-20 18:57:50.298 INFO 2800 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization
AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2016-02-20 18:57:50.887 INFO 2800 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2016-02-20 18:57:50.891 INFO 2800 --- [ main] Example : Started Example in 2.096 seconds (JVM running for 4.109)
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 38.328 s [INFO] Finished at: 2016-02-20T19:06:06+08:00 [INFO] Final Memory: 24M/319M [INFO] ------------------------------------------------------------------------
使用jar tvf 查看jar包内部结构
1 2 3 4 5 6 7 8 9
➜ springboot jar tvf target/myproject-0.0.1-SNAPSHOT.jar 0 Sat Feb 2019:06:06 CST 2016 META-INF/ 411 Sat Feb 2019:06:06 CST 2016 META-INF/MANIFEST.MF 909 Sat Feb 2018:55:32 CST 2016 Example.class 0 Sat Feb 2019:06:06 CST 2016 META-INF/maven/ 0 Sat Feb 2019:06:06 CST 2016 META-INF/maven/com.example/ 0 Sat Feb 2019:06:06 CST 2016 META-INF/maven/com.example/myproject/ 1871 Sat Feb 2019:04:56 CST 2016 META-INF/maven/com.example/myproject/pom.xml 114 Sat Feb 2019:06:06 CST 2016 META-INF/maven/com.example/myproject/pom.properties