Spring Boot 01补充
博客专区 > miye 的博客 > 博客详情
Spring Boot 01补充
miye 发表于5个月前
Spring Boot 01补充
  • 发表于 5个月前
  • 阅读 18
  • 收藏 1
  • 点赞 0
  • 评论 0

腾讯云 学生专属云服务套餐 10元起购>>>   

启动项目SpringApplication.run

启动Spring Boot项目最简单的方法就是执行下面的方法:

SpringApplication.run(Application.class, args);
  •  

该方法返回一个ApplicationContext对象,使用注解的时候返回的具体类型是AnnotationConfigApplicationContextAnnotationConfigEmbeddedWebApplicationContext,当支持web的时候是第二个。

除了上面这种方法外,还可以用下面的方法:

SpringApplication application = new SpringApplication(Application.class);
application.run(args);
  •  

SpringApplication包含了一些其他可以配置的方法,如果你想做一些配置,可以用这种方式。

除了上面这种直接的方法外,还可以使用SpringApplicationBuilder

new SpringApplicationBuilder()
        .showBanner(false)
        .sources(Application.class)
        .run(args);
  •  

当使用SpringMVC的时候由于需要使用子容器,就需要用到SpringApplicationBuilder,该类有一个child(xxx...)方法可以添加子容器。

运行

在IDE中直接直接执行main方法,然后访问http://localhost:8080即可。

另外还可以用上面提到的mvn,可以打包为可执行jar包,然后执行java -jar xxx.jar

或者执行mvn spring-boot:run运行项目。

项目启动后输出如下日志:

[INFO] Attaching agents: [F:\.m2\repository\org\springframework\springloaded\1.2.5.RELEASE\springloaded-1.2.5.RELEASE.jar]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.3.RELEASE)

2015-12-12 22:26:35.298  INFO 9844 --- [           main] c.github.abel533.springboot.Application  : Starting Application on liuzh-PC with PID 9844 (F:\Liu\IDEA\SpringBoot\spring-boot\target\classes started by liuzh_3nofxnp in F:\Liu\IDEA\SpringBoot\spring-boot)
2015-12-12 22:26:35.332  INFO 9844 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@a38d7a3: startup date [Sat Dec 12 22:26:35 CST 2015]; root of context hierarchy
2015-12-12 22:26:35.734  INFO 9844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2015-12-12 22:26:36.302  INFO 9844 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-12-12 22:26:36.456  INFO 9844 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2015-12-12 22:26:36.457  INFO 9844 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.20
2015-12-12 22:26:36.537  INFO 9844 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2015-12-12 22:26:36.537  INFO 9844 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1207 ms
2015-12-12 22:26:36.941  INFO 9844 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2015-12-12 22:26:36.944  INFO 9844 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-12-12 22:26:36.945  INFO 9844 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-12-12 22:26:37.111  INFO 9844 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@a38d7a3: startup date [Sat Dec 12 22:26:35 CST 2015]; root of context hierarchy
2015-12-12 22:26:37.152  INFO 9844 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto java.lang.String com.github.abel533.springboot.Application.home()
2015-12-12 22:26:37.152  INFO 9844 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/now],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto java.lang.String com.github.abel533.springboot.Application.hehe()
2015-12-12 22:26:37.156  INFO 9844 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" 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)
2015-12-12 22:26:37.156  INFO 9844 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2015-12-12 22:26:37.175  INFO 9844 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-12-12 22:26:37.175  INFO 9844 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-12-12 22:26:37.195  INFO 9844 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-12-12 22:26:37.237  INFO 9844 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2015-12-12 22:26:37.279  INFO 9844 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2015-12-12 22:26:37.280  INFO 9844 --- [           main] c.github.abel533.springboot.Applicati
标签: Spring Boot
共有 人打赏支持
粉丝 5
博文 71
码字总数 24957
×
miye
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: