spring-boot环境搭建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring-boot环境搭建相关的知识,希望对你有一定的参考价值。

新建manv工程:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>spring-boot</groupId>
    <artifactId>com.liwen</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--
spring boot 父节点依赖,引入这个之后相关的引入就不需要添加version配置,spring boot会自动选择最合适的版本进行添加。
 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- 指定一下jdk的版本 ,这里我们使用jdk 1.8 ,默认是1.6 -->
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!--
            spring-boot-starter-web: MVC,AOP的依赖包....
         -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--
                <version></version>
                由于我们在上面指定了 parent(spring boot)
             -->
        </dependency>

        <!-- 添加fastjson 依赖包. -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.15</version>
        </dependency>

        <!-- spring boot devtools 依赖包. -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
            <scope>true</scope>
        </dependency>

    </dependencies>

</project>

新建class文件

package com.liwen;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HellCotroller {

    @RequestMapping("/hello")
    public  String Hello()
    {
        return "liwen good!";
    }
}

运行

package com.liwen;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Appmin {

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

结果

"D:Program FilesJavajdk1.8.0_31injava" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=35212 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:Program FilesJetBrainsIntelliJ IDEA 2018.1libidea_rt.jar=35213:D:Program FilesJetBrainsIntelliJ IDEA 2018.1in" -Dfile.encoding=UTF-8 -classpath "D:Program FilesJavajdk1.8.0_31jrelibcharsets.jar;D:Program FilesJavajdk1.8.0_31jrelibdeploy.jar;D:Program FilesJavajdk1.8.0_31jrelibextaccess-bridge-64.jar;D:Program FilesJavajdk1.8.0_31jrelibextc3p0-0.9.1.2.jar;D:Program FilesJavajdk1.8.0_31jrelibextcldrdata.jar;D:Program FilesJavajdk1.8.0_31jrelibextcommons-collections.jar;D:Program FilesJavajdk1.8.0_31jrelibextcommons-dbcp-1.3.jar;D:Program FilesJavajdk1.8.0_31jrelibextcommons-pool.jar;D:Program FilesJavajdk1.8.0_31jrelibextdnsns.jar;D:Program FilesJavajdk1.8.0_31jrelibextjaccess.jar;D:Program FilesJavajdk1.8.0_31jrelibextjfxrt.jar;D:Program FilesJavajdk1.8.0_31jrelibextlocaledata.jar;D:Program FilesJavajdk1.8.0_31jrelibextmysql-connector-java-5.1.7-bin.jar;D:Program FilesJavajdk1.8.0_31jrelibext ashorn.jar;D:Program FilesJavajdk1.8.0_31jrelibextsunec.jar;D:Program FilesJavajdk1.8.0_31jrelibextsunjce_provider.jar;D:Program FilesJavajdk1.8.0_31jrelibextsunmscapi.jar;D:Program FilesJavajdk1.8.0_31jrelibextsunpkcs11.jar;D:Program FilesJavajdk1.8.0_31jrelibextzipfs.jar;D:Program FilesJavajdk1.8.0_31jrelibjavaws.jar;D:Program FilesJavajdk1.8.0_31jrelibjce.jar;D:Program FilesJavajdk1.8.0_31jrelibjfr.jar;D:Program FilesJavajdk1.8.0_31jrelibjfxswt.jar;D:Program FilesJavajdk1.8.0_31jrelibjsse.jar;D:Program FilesJavajdk1.8.0_31jrelibmanagement-agent.jar;D:Program FilesJavajdk1.8.0_31jrelibplugin.jar;D:Program FilesJavajdk1.8.0_31jrelib esources.jar;D:Program FilesJavajdk1.8.0_31jrelib t.jar;D:TOOLIDEASpacecomliwen argetclasses;C:Userslw.m2 epositoryorgspringframeworkootspring-boot-starter-web1.4.3.RELEASEspring-boot-starter-web-1.4.3.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkootspring-boot-starter1.4.3.RELEASEspring-boot-starter-1.4.3.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkootspring-boot-starter-logging1.4.3.RELEASEspring-boot-starter-logging-1.4.3.RELEASE.jar;C:Userslw.m2 epositorychqoslogbacklogback-classic1.1.8logback-classic-1.1.8.jar;C:Userslw.m2 epositorychqoslogbacklogback-core1.1.8logback-core-1.1.8.jar;C:Userslw.m2 epositoryorgslf4jslf4j-api1.7.22slf4j-api-1.7.22.jar;C:Userslw.m2 epositoryorgslf4jjcl-over-slf4j1.7.22jcl-over-slf4j-1.7.22.jar;C:Userslw.m2 epositoryorgslf4jjul-to-slf4j1.7.22jul-to-slf4j-1.7.22.jar;C:Userslw.m2 epositoryorgslf4jlog4j-over-slf4j1.7.22log4j-over-slf4j-1.7.22.jar;C:Userslw.m2 epositoryorgspringframeworkspring-core4.3.5.RELEASEspring-core-4.3.5.RELEASE.jar;C:Userslw.m2 epositoryorgyamlsnakeyaml1.17snakeyaml-1.17.jar;C:Userslw.m2 epositoryorgspringframeworkootspring-boot-starter-tomcat1.4.3.RELEASEspring-boot-starter-tomcat-1.4.3.RELEASE.jar;C:Userslw.m2 epositoryorgapache omcatembed omcat-embed-core8.5.6 omcat-embed-core-8.5.6.jar;C:Userslw.m2 epositoryorgapache omcatembed omcat-embed-el8.5.6 omcat-embed-el-8.5.6.jar;C:Userslw.m2 epositoryorgapache omcatembed omcat-embed-websocket8.5.6 omcat-embed-websocket-8.5.6.jar;C:Userslw.m2 epositoryorghibernatehibernate-validator5.2.4.Finalhibernate-validator-5.2.4.Final.jar;C:Userslw.m2 epositoryjavaxvalidationvalidation-api1.1.0.Finalvalidation-api-1.1.0.Final.jar;C:Userslw.m2 epositoryorgjbossloggingjboss-logging3.3.0.Finaljboss-logging-3.3.0.Final.jar;C:Userslw.m2 epositorycomfasterxmlclassmate1.3.3classmate-1.3.3.jar;C:Userslw.m2 epositorycomfasterxmljacksoncorejackson-databind2.8.5jackson-databind-2.8.5.jar;C:Userslw.m2 epositorycomfasterxmljacksoncorejackson-annotations2.8.5jackson-annotations-2.8.5.jar;C:Userslw.m2 epositorycomfasterxmljacksoncorejackson-core2.8.5jackson-core-2.8.5.jar;C:Userslw.m2 epositoryorgspringframeworkspring-web4.3.5.RELEASEspring-web-4.3.5.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkspring-aop4.3.5.RELEASEspring-aop-4.3.5.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkspring-beans4.3.5.RELEASEspring-beans-4.3.5.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkspring-context4.3.5.RELEASEspring-context-4.3.5.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkspring-webmvc4.3.5.RELEASEspring-webmvc-4.3.5.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkspring-expression4.3.5.RELEASEspring-expression-4.3.5.RELEASE.jar;C:Userslw.m2 epositorycomalibabafastjson1.2.15fastjson-1.2.15.jar;C:Userslw.m2 epositoryorgspringframeworkootspring-boot-devtools1.4.3.RELEASEspring-boot-devtools-1.4.3.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkootspring-boot1.4.3.RELEASEspring-boot-1.4.3.RELEASE.jar;C:Userslw.m2 epositoryorgspringframeworkootspring-boot-autoconfigure1.4.3.RELEASEspring-boot-autoconfigure-1.4.3.RELEASE.jar" com.liwen.Appmin

. _ _
/ /
‘_ ()
( ( )
| ‘ | ‘| | ‘ / ` |
/ _)| |)| | | | | || (| | ) ) ) )
‘ |__
| .|| ||| |, | / / / /
=========|_|==============|__/=////
:: Spring Boot :: (v1.4.3.RELEASE)

2018-06-08 20:31:05.284 INFO 47016 --- [ restartedMain] com.liwen.Appmin : Starting Appmin on liwen-pc with PID 47016 (D:TOOLIDEASpacecomliwen argetclasses started by lw in D:TOOLIDEASpacecomliwen)
2018-06-08 20:31:05.288 INFO 47016 --- [ restartedMain] com.liwen.Appmin : No active profile set, falling back to default profiles: default
2018-06-08 20:31:05.539 INFO 47016 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]7a5c4347: startup date [Fri Jun 08 20:31:05 CST 2018]; root of context hierarchy
2018-06-08 20:31:07.800 INFO 47016 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-06-08 20:31:07.813 INFO 47016 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service Tomcat
2018-06-08 20:31:07.814 INFO 47016 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
2018-06-08 20:31:07.929 INFO 47016 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-06-08 20:31:07.929 INFO 47016 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2395 ms
2018-06-08 20:31:08.160 INFO 47016 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: ‘dispatcherServlet‘ to [/]
2018-06-08 20:31:08.167 INFO 47016 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘characterEncodingFilter‘ to: [/]
2018-06-08 20:31:08.168 INFO 47016 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘hiddenHttpMethodFilter‘ to: [/
]
2018-06-08 20:31:08.168 INFO 47016 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘httpPutFormContentFilter‘ to: [/]
2018-06-08 20:31:08.168 INFO 47016 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: ‘requestContextFilter‘ to: [/
]
2018-06-08 20:31:08.709 INFO 47016 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]7a5c4347: startup date [Fri Jun 08 20:31:05 CST 2018]; root of context hierarchy
2018-06-08 20:31:08.809 INFO 47016 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.liwen.HellCotroller.Hello()
2018-06-08 20:31:08.815 INFO 47016 --- [ restartedMain] 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-06-08 20:31:08.816 INFO 47016 --- [ restartedMain] 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-06-08 20:31:08.889 INFO 47016 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-08 20:31:08.889 INFO 47016 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/
] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-08 20:31:09.035 INFO 47016 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-08 20:31:09.342 INFO 47016 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-06-08 20:31:09.441 INFO 47016 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-06-08 20:31:09.512 INFO 47016 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-06-08 20:31:09.524 INFO 47016 --- [ restartedMain] com.liwen.Appmin : Started Appmin in 5.379 seconds (JVM running for 11.402)
2018-06-08 20:31:49.510 INFO 47016 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet ‘dispatcherServlet‘
2018-06-08 20:31:49.510 INFO 47016 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet ‘dispatcherServlet‘: initialization started
2018-06-08 20:31:49.536 INFO 47016 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet ‘dispatcherServlet‘: initialization completed in 26 ms
技术分享图片

以上是关于spring-boot环境搭建的主要内容,如果未能解决你的问题,请参考以下文章

spring-boot入门之一——环境搭建

解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE(转)(代码片段

spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段

Spring-Boot - 初步搭建

node 环境下简单web服务器搭建代码

SpringBoot 环境搭建