欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

第一个SpringBoot应用

程序员文章站 2022-06-17 16:14:17
...

一、新建maven应用

第一个SpringBoot应用

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

二、工程目录结构
第一个SpringBoot应用

二、配置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.bootaaa@qq.com5c6648b0: 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.bootaaa@qq.com5c6648b0: 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/
第一个SpringBoot应用

相关标签: springboot