- 创建一个Maven项目
eclipse右键新建Maven Project
默认一直下一步即可 - 修改pom.xml
4.0.0
cn.moexc
boot
0.0.1-SNAPSHOT
jar
boot
http://maven.apache.org
UTF-8
org.springframework.boot
spring-boot-starter-parent
2.0.5.RELEASE
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-devtools
true
org.springframework.boot
spring-boot-maven-plugin
true
等待jar包下载完毕....
新建yml文件
在/src/main/resources目录下新建一个application.yml并填写:
server:
#监听端口
port: 80
servlet:
#工程名
context-path: /boot
- 修改启动类
启动类添加注解@SpringBootApplication
把main方法中修改为
SpringApplication.run(App.class, args);
完整的启动类:
package cn.moexc.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Hello world!
*
*/
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
-
右键启动
控制台输出:
16:57:33.698 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
16:57:33.700 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/, /spring-boot/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter/target/classes/]
16:57:33.700 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/E:/Work/boot/boot/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)
2018-12-25 16:57:33.983 INFO 3748 --- [ restartedMain] cn.moexc.boot.App : Starting App on DESKTOP-J57AL42 with PID 3748 (E:\Work\boot\boot\target\classes started by DemonMagic in E:\Work\boot\boot)
2018-12-25 16:57:33.984 INFO 3748 --- [ restartedMain] cn.moexc.boot.App : No active profile set, falling back to default profiles: default
2018-12-25 16:57:34.020 INFO 3748 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@17584257: startup date [Tue Dec 25 16:57:34 CST 2018]; root of context hierarchy
2018-12-25 16:57:35.309 INFO 3748 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 80 (http)
2018-12-25 16:57:35.332 INFO 3748 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-12-25 16:57:35.332 INFO 3748 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-12-25 16:57:35.342 INFO 3748 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_191\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_191/bin/server;C:/Program Files/Java/jre1.8.0_191/bin;C:/Program Files/Java/jre1.8.0_191/lib/amd64;E:\Software\Oracle\product\11.2.0\dbhome_1\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Java\jdk1.8.0_191\bin;C:\Program Files\Java\jdk1.8.0_191\jre\bin;E:\Software\Maven\bin; ;C:\Users\DemonMagic\AppData\Local\Microsoft\WindowsApps;;C:\Windows\System32;;.]
2018-12-25 16:57:35.419 INFO 3748 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/boot] : Initializing Spring embedded WebApplicationContext
2018-12-25 16:57:35.419 INFO 3748 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1402 ms
2018-12-25 16:57:35.468 INFO 3748 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-12-25 16:57:35.471 INFO 3748 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-12-25 16:57:35.472 INFO 3748 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-12-25 16:57:35.472 INFO 3748 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-12-25 16:57:35.472 INFO 3748 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-12-25 16:57:35.565 INFO 3748 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-25 16:57:35.696 INFO 3748 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@17584257: startup date [Tue Dec 25 16:57:34 CST 2018]; root of context hierarchy
2018-12-25 16:57:35.767 INFO 3748 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-12-25 16:57:35.768 INFO 3748 --- [ 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.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-12-25 16:57:35.794 INFO 3748 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-25 16:57:35.794 INFO 3748 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-25 16:57:35.930 INFO 3748 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-12-25 16:57:35.955 INFO 3748 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-12-25 16:57:36.041 INFO 3748 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 80 (http) with context path '/boot'
2018-12-25 16:57:36.045 INFO 3748 --- [ restartedMain] cn.moexc.boot.App : Started App in 2.336 seconds (JVM running for 2.732)
当然还有更简单方法:
只需要填写项目名就可以,还可以按照需要构造pom,一步到位:在线生成
OK :)