1, Pom configuration method
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"3 xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">4 <modelversion>4.0.0</modelversion>5 6 <groupId>Com.springboot</groupId>7 <Artifactid>Quick_start</Artifactid>8 <version>0.0.1-snapshot</version>9 <Packaging>Jar</Packaging>Ten One <name>Quick_start</name> A <URL>http://maven.apache.org</URL> - <Description>Demo Project for Spring Boot</Description> - the <Properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <Maven.compiler.source>1.8</Maven.compiler.source> + <Maven.compiler.target>1.8</Maven.compiler.target> - <java.version>1.8</java.version> + </Properties> A at <Dependencies> - <!--dependency is not used with the parent method, the scope and type settings are required - - <Dependency> - <groupId>Org.springframework.boot</groupId> - <Artifactid>Spring-boot-dependencies</Artifactid> - <version>2.0.2.RELEASE</version> in <Scope>Import</Scope> - <type>Pom</type> to </Dependency> + - the <Dependency> * <groupId>Org.springframework.boot</groupId> $ <Artifactid>Spring-boot-starter-web</Artifactid>Panax Notoginseng </Dependency> - the <Dependency> + <groupId>Org.springframework.boot</groupId> A <Artifactid>Spring-boot-starter-test</Artifactid> the <Scope>Test</Scope> + </Dependency> - </Dependencies> $ $ <Build> - <Plugins> - <plugin> the <groupId>Org.springframework.boot</groupId> - <Artifactid>Spring-boot-maven-plugin</Artifactid>Wuyi </plugin> the </Plugins> - </Build> Wu - About </Project>
View Code
2, the entity class writing
1 PackageCom.springboot;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 ImportOrg.springframework.context.ConfigurableApplicationContext;6 ImportOrg.springframework.context.annotation.Bean;7 8 /******************************9 * @Author: LiuyangTen * @ClassName: Quickstartapplication One * @Date: 20,185 months A * @Time: 01:05:59 - * @Type: Springboot - * @Version: 1.0 the * @Return: - * @Description: - *******************************/ - + @SpringBootApplication - Public classquickstartapplication { + A @Bean at PublicRunnable createrunnable () { - - return() { -System.out.println ("Spring Boot is Run"); - }; - in } - to Public Static voidMain (string[] args) { +Configurableapplicationcontext ApplicationContext = Springapplication.run (quickstartapplication.class, args); -Applicationcontext.getbean (Runnable.class). Run (); the } *}
View Code
SOURCE Storage:
The parent section needs to be commented out
Https://github.com/liushaoye/quick_start
SpringBoot2.0.2 does not use the parent as a MAVEN single-inheritance operation: Org.springframework.boot:spring-boot-dependencies:2.0.2.release