SpringBoot learning portal - Create a simple Maven project

First, a brief look at SpringBoot:

  SpringBoot is a rapid development framework, can help us to quickly integrate third-party frameworks (mainly by means of Maven dependencies), complete with annotations, to streamline XML configuration, built-in embedded Http server (Tomcat, Jetty), the default embedded Tomcat server, final the Java application execution.

SpringBoot benefits:

  1, a simplified Maven, only one or two can be achieved dependent frame Spring + SpringMvc

  2, automatic configuration Spring, rapid construction projects, eliminating configuration file

  3, zero-configuration, annotation of, greater than the agreed configuration simplifies the operation XML

  4, no mainstream configuration integrated development framework

================================================== ======'s get started, oh ====================================== =======================

Note: the environmental requirements SpringBoot: jdk environment is 1.8 and above; use maven for development.

First, create a maven project (Maven Project) tick the first option, we want to create a simple project, the next point next

  

 

Marked with the package name and project name Click Finish to complete

 

  

 

 

The initial structure

 

  

 

 

 Second, the introduction of the Boot-dependent SpringBoot

  Interim dependence are: Parent module dependencies: Spring-boot-start-parent 

        Start-dependent: Spring-boot-start-web

        Test dependence : Spring-boot-start-test

        Hot deployment dependent: Spring-boot-devtools

(This is dependent on where the pom.xml will download something after the introduction of dependence, which is a normal phenomenon)

(After the introduction of dependence, the project will complain. Right-click on the project, find maven click Update Project, select the current project, check on the spot ok project would not be incorrect report)

 

 

 <-! Pom.xml dependent ->

<!-- Spring Boot 启动父依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath />
</parent>
<!-- 项目设置:编码格式UTF-8 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- @ConfigurationProperties注解依赖 -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
-->

<!--单元测试依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<!-- Spring Boot SpringMVC框架依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Boot 测试依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<! - hot deployment ->
<dependency>
<the groupId> org.springframework.boot </ the groupId>
<the artifactId> Boot-Spring-DevTools </ the artifactId>
<optional> to true </ optional>
<! - = optional true, rely not passed, the project relies devtools; dependence myboot project after project if you want to use devtools, need to re-introduce ->
<scope> to true </ scope> <- hot deployment ->!
</ dependency >
</ Dependencies>

<build>
<plugins>
<!-- SpringBoot插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!-- SpringBoot打jar包名称 -->
<finalName>demo</finalName>
</build>

 

Third, create SpringBoot entry function

Creating a Class class in src / main / java in

(Because he wrote the entity class entity in future projects such as: com.wy1.entity so when the entry function to define the package name of the package in the entity above example: com.wy1)

 

 

After creating the entry function class, the class to write on SpringBoot entry function Notes: @SpringBootApplication 

 

The method of writing which main class

 

 

 

(Generating a main shortcut mainAlt + / select the second)

Fourth, create a controller Controller output content like page showing the effect (the same package name but also in the name of an entry function package)

  

 

 

Written Controller

 

 

 

 

 

Fifth, run the project to see the results (two direct hit run jar package runs)

 

  There are two ways to run the project in the sts

 

    1, the selected item right Run As ---> SpringBoot App

 

    2, find the right instrument panel to select the current project (Re) start

 

      

 

 

 

 The console is not being given the attention that is ok: Project default port number is 8080; the default access address is not the name of the project is no project addresses 

 

 

 effect:

  

 

Then there is a way to publish a project labeled jar

Turn off the console, add SpringBoot plug-in dependencies in pom.xml (above pom dependent on there)

 

 

 

Then select the right project run As 4 Maven build type the command clean package click on run

 

 

When the console appears BUILD SUCCESS, on behalf of success

 

 

 

As the jar package in the target file folder to put it to refresh the target folder (refresh target folder: Right target select Refresh)

 

 

 

 

 

Jar packets copied to a file open cmd black window

Because I'm on the d drive test folder so first cut to the D drive, then into the test folder inside the importation of java -jar demo.jar (demo.jar demo jar package name their own plays)

 

 

 Such is the success of the operation and effect as the above renderings

 

 

 

Close is running ctrl + c

 

 

 OK so we also put a simple maven project run up.

  SpringBoot is a rapid development framework, can help us to quickly integrate third-party frameworks (mainly by means of Maven dependencies), complete with annotations, to streamline XML configuration, built-in embedded Http server (Tomcat, Jetty), the default embedded Tomcat server, final the Java application execution.

SpringBoot benefits:

  1, a simplified Maven, only one or two can be achieved dependent frame Spring + SpringMvc

  2, automatic configuration Spring, rapid construction projects, eliminating configuration file

  3, zero-configuration, annotation of, greater than the agreed configuration simplifies the operation XML

  4, no mainstream configuration integrated development framework

================================================== ======'s get started, oh ====================================== =======================

Note: the environmental requirements SpringBoot: jdk environment is 1.8 and above; use maven for development.

First, create a maven project (Maven Project) tick the first option, we want to create a simple project, the next point next

  

 

Marked with the package name and project name Click Finish to complete

 

  

 

 

The initial structure

 

  

 

 

 Second, the introduction of the Boot-dependent SpringBoot

  Interim dependence are: Parent module dependencies: Spring-boot-start-parent 

        Start-dependent: Spring-boot-start-web

        Test dependence : Spring-boot-start-test

        Hot deployment dependent: Spring-boot-devtools

(This is dependent on where the pom.xml will download something after the introduction of dependence, which is a normal phenomenon)

(After the introduction of dependence, the project will complain. Right-click on the project, find maven click Update Project, select the current project, check on the spot ok project would not be incorrect report)

 

 

 <-! Pom.xml dependent ->

<!-- Spring Boot 启动父依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath />
</parent>
<!-- 项目设置:编码格式UTF-8 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- @ConfigurationProperties注解依赖 -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
-->

<!--单元测试依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<!-- Spring Boot SpringMVC框架依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Boot 测试依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<! - hot deployment ->
<dependency>
<the groupId> org.springframework.boot </ the groupId>
<the artifactId> Boot-Spring-DevTools </ the artifactId>
<optional> to true </ optional>
<! - = optional true, rely not passed, the project relies devtools; dependence myboot project after project if you want to use devtools, need to re-introduce ->
<scope> to true </ scope> <- hot deployment ->!
</ dependency >
</ Dependencies>

<build>
<plugins>
<!-- SpringBoot插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!-- SpringBoot打jar包名称 -->
<finalName>demo</finalName>
</build>

 

Third, create SpringBoot entry function

Creating a Class class in src / main / java in

(Because he wrote the entity class entity in future projects such as: com.wy1.entity so when the entry function to define the package name of the package in the entity above example: com.wy1)

 

 

After creating the entry function class, the class to write on SpringBoot entry function Notes: @SpringBootApplication 

 

The method of writing which main class

 

 

 

(Generating a main shortcut mainAlt + / select the second)

Fourth, create a controller Controller output content like page showing the effect (the same package name but also in the name of an entry function package)

  

 

 

Written Controller

 

 

 

 

 

Fifth, run the project to see the results (two direct hit run jar package runs)

 

  There are two ways to run the project in the sts

 

    1, the selected item right Run As ---> SpringBoot App

 

    2, find the right instrument panel to select the current project (Re) start

 

      

 

 

 

 The console is not being given the attention that is ok: Project default port number is 8080; the default access address is not the name of the project is no project addresses 

 

 

 effect:

  

 

Then there is a way to publish a project labeled jar

Turn off the console, add SpringBoot plug-in dependencies in pom.xml (above pom dependent on there)

 

 

 

Then select the right project run As 4 Maven build type the command clean package click on run

 

 

When the console appears BUILD SUCCESS, on behalf of success

 

 

 

As the jar package in the target file folder to put it to refresh the target folder (refresh target folder: Right target select Refresh)

 

 

 

 

 

Jar packets copied to a file open cmd black window

Because I'm on the d drive test folder so first cut to the D drive, then into the test folder inside the importation of java -jar demo.jar (demo.jar demo jar package name their own plays)

 

 

 Such is the success of the operation and effect as the above renderings

 

 

 

Close is running ctrl + c

 

 

 OK so we also put a simple maven project run up.

Guess you like

Origin www.cnblogs.com/y-sy/p/12456266.html