SpringBoot快速入门(非maven)

来源:互联网 发布:java调用函数返回值 编辑:程序博客网 时间:2024/06/06 02:43

SpringBoot

环境准备

1. java环境(jdk1.8.0_111

2. Java EE IDEeclipse-jee-neon-RC3-win32-x86_64

3. Springboot所需jar包(30个)

项目结构

代码实例

package hello;import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;@Controller@EnableAutoConfigurationpublic class SampleController {    @RequestMapping("/")    @ResponseBody    String home() {        return "Hello World!";    }    public static void main(String[] args) throws Exception {        SpringApplication.run(SampleController.class, args);    }}


运行结果

 

  .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v1.4.2.RELEASE)2017-01-24 10:39:47.403  INFO 717060 --- [           main] hello.SampleController                   : Starting SampleController on GL with PID 717060 (G:\WorkSoft\workspace-neon\demo\bin started by GL-PC in G:\WorkSoft\workspace-neon\demo)2017-01-24 10:39:47.412  INFO 717060 --- [           main] hello.SampleController                   : No active profile set, falling back to default profiles: default2017-01-24 10:39:47.478  INFO 717060 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@10e41621: startup date [Tue Jan 24 10:39:47 CST 2017]; root of context hierarchy2017-01-24 10:39:51.044  INFO 717060 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)2017-01-24 10:39:51.062  INFO 717060 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat2017-01-24 10:39:51.064  INFO 717060 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.62017-01-24 10:39:51.276  INFO 717060 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2017-01-24 10:39:51.276  INFO 717060 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3805 ms2017-01-24 10:39:51.618  INFO 717060 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]2017-01-24 10:39:51.624  INFO 717060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]2017-01-24 10:39:51.625  INFO 717060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]2017-01-24 10:39:51.625  INFO 717060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]2017-01-24 10:39:51.627  INFO 717060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]2017-01-24 10:39:52.094  INFO 717060 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@10e41621: startup date [Tue Jan 24 10:39:47 CST 2017]; root of context hierarchy2017-01-24 10:39:52.199  INFO 717060 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String hello.SampleController.home()2017-01-24 10:39:52.217  INFO 717060 --- [           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-01-24 10:39:52.218  INFO 717060 --- [           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-01-24 10:39:52.293  INFO 717060 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-01-24 10:39:52.293  INFO 717060 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-01-24 10:39:52.375  INFO 717060 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-01-24 10:39:52.658  INFO 717060 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup2017-01-24 10:39:52.764  INFO 717060 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)2017-01-24 10:39:52.776  INFO 717060 --- [           main] hello.SampleController                   : Started SampleController in 5.95 seconds (JVM running for 6.511)2017-01-24 10:41:17.322  INFO 717060 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'2017-01-24 10:41:17.323  INFO 717060 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started2017-01-24 10:41:17.361  INFO 717060 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 38 ms

在浏览器访问 http://localhost:8080/

 

下载demo

http://download.csdn.net/detail/xiejianwei2016/9744086

1 0