第一个SpringBoot应用

一、新建maven应用

这里写图片描述

  • 不需要web应用,选择普通quickstart应用即可

二、工程目录结构
这里写图片描述

二、配置pom.xml文件

    <!-- Spring boot 父引用-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>

    <!-- Spring boot 核心web-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

三、新建控制层(controller类)

@Controller
@EnableAutoConfiguration
public class TestBootController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
    return "hello world";
    }

    public static void main(String[] args) throws Exception {
    SpringApplication.run(TestBootController.class, args);
    }
}

四、在包的外层增加Application

@EnableAutoConfiguration
@ComponentScan(basePackages={"com.kx.springboot"})
public class Application {
    public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
    }
}

五、启动Application类的mian函数


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

2018-03-12 11:39:43.110 [main] INFO  com.xinrui.nlp.Application -
                Starting Application on MZKJ-PC-00934 with PID 7548 (E:\dl-workspace\ai-nlp\target\classes started by liangzhicheng in E:\dl-workspace\ai-nlp)
2018-03-12 11:39:43.112 [main] INFO  com.xinrui.nlp.Application -
                No active profile set, falling back to default profiles: default
2018-03-12 11:39:43.138 [main] INFO  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext -
                Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5c6648b0: startup date [Mon Mar 12 11:39:43 CST 2018]; root of context hierarchy
2018-03-12 11:39:43.306 [background-preinit] INFO  org.hibernate.validator.internal.util.Version -
                HV000001: Hibernate Validator 5.2.4.Final
2018-03-12 11:39:43.733 [main] WARN  org.mybatis.spring.mapper.ClassPathMapperScanner -
                No MyBatis mapper was found in '[com.xinrui.nlp.controller, com.xinrui.nlp]' package. Please check your configuration.
2018-03-12 11:39:43.926 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker -
                Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$7308a24f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-12 11:39:44.284 [main] INFO  o.s.b.c.e.tomcat.TomcatEmbeddedServletContainer -
                Tomcat initialized with port(s): 8080 (http)
2018-03-12 11:39:44.292 [main] INFO  org.apache.catalina.core.StandardService -
                Starting service Tomcat
2018-03-12 11:39:44.293 [main] INFO  org.apache.catalina.core.StandardEngine -
                Starting Servlet Engine: Apache Tomcat/8.5.4
2018-03-12 11:39:44.366 [localhost-startStop-1] INFO  o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] -
                Initializing Spring embedded WebApplicationContext
2018-03-12 11:39:44.367 [localhost-startStop-1] INFO  org.springframework.web.context.ContextLoader -
                Root WebApplicationContext: initialization completed in 1229 ms
2018-03-12 11:39:44.497 [localhost-startStop-1] INFO  o.s.boot.web.servlet.ServletRegistrationBean -
                Mapping servlet: 'dispatcherServlet' to [/]
2018-03-12 11:39:44.502 [localhost-startStop-1] INFO  o.s.boot.web.servlet.FilterRegistrationBean -
                Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-12 11:39:44.502 [localhost-startStop-1] INFO  o.s.boot.web.servlet.FilterRegistrationBean -
                Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-03-12 11:39:44.502 [localhost-startStop-1] INFO  o.s.boot.web.servlet.FilterRegistrationBean -
                Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-03-12 11:39:44.502 [localhost-startStop-1] INFO  o.s.boot.web.servlet.FilterRegistrationBean -
                Mapping filter: 'requestContextFilter' to: [/*]
2018-03-12 11:39:44.726 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter -
                Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5c6648b0: startup date [Mon Mar 12 11:39:43 CST 2018]; root of context hierarchy
2018-03-12 11:39:44.783 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping -
                Mapped "{[/num]}" onto public int com.xinrui.nlp.controller.TestBootController.home()
2018-03-12 11:39:44.784 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping -
                Mapped "{[/get]}" onto com.xinrui.nlp.bean.User com.xinrui.nlp.controller.TestBootController.getUser()
2018-03-12 11:39:44.787 [main] INFO  o.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)
2018-03-12 11:39:44.787 [main] INFO  o.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)
2018-03-12 11:39:44.815 [main] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping -
                Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-12 11:39:44.815 [main] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping -
                Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-12 11:39:44.849 [main] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping -
                Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-12 11:39:45.164 [main] INFO  o.s.jmx.export.annotation.AnnotationMBeanExporter -
                Registering beans for JMX exposure on startup
2018-03-12 11:39:45.175 [main] INFO  org.apache.coyote.http11.Http11NioProtocol -
                Initializing ProtocolHandler ["http-nio-8080"]
2018-03-12 11:39:45.182 [main] INFO  org.apache.coyote.http11.Http11NioProtocol -
                Starting ProtocolHandler [http-nio-8080]
2018-03-12 11:39:45.192 [main] INFO  org.apache.tomcat.util.net.NioSelectorPool -
                Using a shared selector for servlet write/read
2018-03-12 11:39:45.204 [main] INFO  o.s.b.c.e.tomcat.TomcatEmbeddedServletContainer -
                Tomcat started on port(s): 8080 (http)
2018-03-12 11:39:45.206 [main] INFO  com.xinrui.nlp.Application -
                Started Application in 2.36 seconds (JVM running for 2.834)
2018-03-12 11:39:59.335 [http-nio-8080-exec-1] INFO  o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] -
                Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-03-12 11:39:59.335 [http-nio-8080-exec-1] INFO  org.springframework.web.servlet.DispatcherServlet -
                FrameworkServlet 'dispatcherServlet': initialization started
2018-03-12 11:39:59.349 [http-nio-8080-exec-1] INFO  org.springframework.web.servlet.DispatcherServlet -
                FrameworkServlet 'dispatcherServlet': initialization completed in 13 ms

六、访问http://localhost:8080/
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

两只橙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值